angularjs - Maximum call stack size exceeded using angular ng-view -
i want redirect after login /dashboard
$scope.submit = function (user) { if ($scope.loginform.$valid) { userservice.login(user).then( function (result) { $location.path('/dashboard'); }, function (reason) { $scope.msg = "username or password not correct"; }); $scope.reset(); } };
in app.js want create menu dynamically , show dashboard.html
$routeprovider .when('/dashboard', { templateurl: 'views/dashboard.html', abstract:true, resolve: { menu: function (menuservice) { return menuservice.getmenu(); } }, controller: function ($scope, menu) { $scope.menu = menu; $scope.oneatatime = true; } })
and in dashboard use ng-view load template
<div class="content"> <div class="container"> <ng-view></ng-view> </div>
but catch "maximum call stack size exceeded" error.
the menuservice servie return promise
factory('menuservice', function ($q, $http) { var getmenu = function () { var deferred = $q.defer(); $http.post('/menu', 1). success(function (data) { deferred.resolve(data); }). error(function (data, status) { deferred.reject(status); }); return deferred.promise; }; return{ getmenu: getmenu }
})
i changed menuservice.getmenu() this:
$routeprovider .when('/dashboard', { templateurl: 'views/dashboard.html', abstract:true, resolve: { menu: function (menuservice) { menuservice.getmenu().then(function(result){ return result; }); } }, controller: function ($scope, menu) { $scope.menu = menu; $scope.oneatatime = true; } })
and dashboard loaded without menu. method called after dashboard.html loading!!!!
when remove ng-view every thing work perfectly.
what problem? thank you
basically need change in custom resolve
service code. controller promise has receiving chain promise, should return promise
instead of return chain promise
.
code
$routeprovider .when('/dashboard', { templateurl: 'views/dashboard.html', abstract:true, resolve: { menu: function (menuservice) { return menuservice.getmenu(); } }, controller: function ($scope, menu) { menu.then(function(data){ $scope.menu = data; }); $scope.oneatatime = true; } })
Comments
Post a Comment