javascript - angular more function in function in controller -


i got task make http request angular. new angular, , hot specific rules how should done app. can tell me possible describe or not, , if possible how?

in view need have couple of buttons or regular links call functions in controller. need 1 controller more 1 function, , need data each function available when call made. made on function in controller:

(function() { 'use strict';  angular     .module('usermanager')     .controller('userdatacontroller', userdatacontroller);   function userdatacontroller(auth, $scope,$http){      var vm = this;     vm.loggeduser = auth;     vm.allusers=[];      function allusersget() {         $http({             method: 'get',             url: 'http://localhost:3000/users/allusers',             headers: {                 'content-type': 'application/json'             }         }).then(function (response) {             vm.allusers = response.data;         });     }  } })(); 

but cannot data in view. can tell me how write link in view , data printing, , need change function in controller little bit?

thanks in advance

you can use controller in template this:

<div ng-controller="userdatacontroller $ctrl">     <button ng-click="$ctrl.allusersget()">get users data</button>     <pre>     {{ $ctrl.allusers }}     </pre> </div> 

you migtht want bind allusersget function controller. instead of

function allusersget() { ... 

write

this.allusersget = function() { ... 

Comments