Friday, November 15, 2013

ng-click in Angular

<a style="cursor: pointer;" ng-click="review(state.id)">{{state.status}}</a>

 
 

If you make an "a" tag like this, you will not immediately get the pointer cursor style so you may want to add it. The ng-click in Angular lets you run a function back in your controller when you click an "a" tag. An example of such a function:

$scope.review = function(obj) {
   $state.go("review", {status: obj});
}

 
 

This function would require you to have $scope and $state specified at your controller's signature.

assetControllers.controller('statusCtrl', ['$scope', '$state',
   function statusCtrl($scope, $state) {

 
 

The act our function facilitates is to allow one to pass a "status" parameter to a controller. In app.js I have defined "status" and also "search" as parameters one may hand stuff into (for "review") like so:

.state('review', {
   url: "/review?search&status",
   templateUrl: "templates/search.html",
   controller: "searchCtrl"
})

No comments:

Post a Comment