Currently, I am attempting to extract the text inside a <p>
element within my Angular application and pass it on to both a method and a view using ng-route
. The objective is that when a user clicks on the <p>
, the innerText will be sent through a method, fetch some data in return, and eventually display a new view containing the response data.
<p ng-click="searchUser()">Bob Ross</p>
JavaScript code:
var app = angular.module('app', ['ngRoute'])
.config(['$routeProvider', function($routeProvider){
.when('/searchUser:name', {
templateUrl: 'user-results.html',
controller: 'searchController'
})
app.controller('searchController', function($scope, $routeParams) {
$scope.name = $routeParams.name;
$scope.searchUser = function(){
// do some stuff;
}
});
I am currently unsure about the correct approach to capture the inner text of the <p>
tag accurately and then passing it through the method (I might be missing the mark completely); should I bind it to my model first and then send it as a routeparam?
Your assistance on this matter would be greatly appreciated!