Thursday, December 12, 2013

Put a method in an AngularJS controller!

I am jamming a method into the controller I made here:

assetControllers.controller('fooCtrl', ['$scope', '$state', '$stateParams', '$modal',
   function fooCtrl($scope, $state, $stateParams, $modal) {
      var myid = $stateParams.id;
      $scope.things = [];
      $scope.things.push({asgiven: myid, asaddedtoself: myid + myid});
      
      $scope.whatever = function() {
         alert('whatever');
      }
}]);

 
 

I may call it from the click of a button if the button (in the appropriate template) looks like so:

<button class="btn btn-default" ng-click="whatever()">Cancel</button>

No comments:

Post a Comment