javascript - Undefined variable passing data using service -
i have declared app , have 1 controller (for demonstration purposes):
var module = angular.module("app", []) module.controller("modalctrl", ["$scope", function ($scope, dataservice) { $scope.printentity = function () { console.log(dataservice.getentityarray()); } }]);
and service:
module.factory("dataservice", function () { var entityarrayservice = [1,2]; return { getentityarray: function () { return entityarrayservice; } }; });
when call $scope.printentity
view, i'm told dataservice.getentityarray()
undefined.
i've loaded service dependency , declared entityarrayservice array outside of return statement. i've looked high , low answer no avail. goal share piece of data between 2 controllers, @ minute can't use 1 controller retrieve data.
the service isn't loaded dependency. change line:
module.controller("modalctrl", ["$scope", function ($scope, dataservice) {
to this:
module.controller("modalctrl", ["$scope", "dataservice", function ($scope, dataservice) {
Comments
Post a Comment