javascript - how can i call function inside angular js and use its value in outer function? -


i having code of pagination want update not able call callapi function inside function.below code of that.and want use value of callapi function in outer function

 (function() {      'use strict';    angular         .module('app', [])        .factory('pagerservice', pagerservice)         .controller('examplecontroller', examplecontroller);       function examplecontroller(pagerservice) {         var vm = this;          function callapi($scope,$http) {             $http({                 method:'get',                 url:'https://jsonplaceholder.typicode.com/posts/1',              }).             then(function (response) {                 $scope.sample = response.data;                 $scope.count = response.data;              })          }          vm.dummyitems = _.range(1, 151); // dummy array of items paged         vm.pager = {};         vm.setpage = setpage; 

you need inject $scope, $http controller, , remove callapi() method. should data.

see working fiddle

update

updated fiddle link same controller , user of data in other event. link


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -