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

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -