javascript - Angular Service can set data from one controller but not the other -


i have module , 2 controllers :

var module = angular.module("app", ["aggrid", "nganimate", "ngsanitize", "ngdialog"])   module.controller("mainctrl", ["$scope", "dataservice","$timeout","datefilter","ngdialog", "$http", function ($scope, $http, $timeout, datefilter, ngdialog, dataservice) { }]);   module.controller("modalctrl", ["$scope", "ngdialog", "dataservice", function ($scope, ngdialog, dataservice) {   $scope.printentity = function () {     console.log(dataservice.getentityarray()); }  }]); 

and service:

 module.factory("dataservice", function () {  var entityarrayservice = [];  return {     setentityarray: function (entityarray) {         entityarrayservice = entityarray;     },     getentityarray: function () {         return entityarrayservice;     }  };  }); 

i can call dataservice.setentityarray(array) inside second controller, when try call first controller tells me dataservice.setentityarray not function

the order of dependency injections incorrect. arguments in controller function must repeat order of elements in array. in case dataservice second argument:

module.controller("mainctrl", ["$scope", "dataservice","$timeout","datefilter","ngdialog", "$http", function ($scope, dataservice, $timeout, datefilter, ngdialog, $http) { }]); 

Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -