Saturday, 15 February 2014

javascript - angularjs scope variable is not updating in routeChangeSuccess -



javascript - angularjs scope variable is not updating in routeChangeSuccess -

angularjs starting point app.js

.config(function ($routeprovider,$interpolateprovider,$locationprovider) { $routeprovider .when('/', { templateurl: 'views/main.html', controller: 'mainctrl' }) .when('/page/:pageid', { templateurl: function (params) { homecoming 'views/' + params.pageid + 'detail.html'; }, controller: 'pagectrl' }). .otherwise({ redirectto: '/' });

pagectrl js file

.controller('pagectrl', function ($scope,$http,$timeout,$location,$rootscope,$filter) { $scope.currentrouteinpagectrl = ""; $scope.$on('$routechangesuccess', function (scope, next, current) { console.log('total ......route slug : ' + object.keys(next.params).length); console.log(next.params.pageid); $scope.currentrouteinpagectrl = next.params.pageid; console.log($scope.currentrouteinpagectrl); }); $( window ).scroll(function() { console.log($scope.currentrouteinpagectrl); }); });

when alter route dynamically /page/food , /page/story $scope.currentrouteinpagectrl taking both value nutrient , story in window scroll event

i thought there no need of stil, tried $scope.apply() give me digest error tried $rootscope.$$phase || $rootscope.$apply();

i tried path $location.path() still facing same issue

thanks in advance

javascript angularjs callback angularjs-scope javascript-databinding

No comments:

Post a Comment