How to Forward $scope from Controller to Controller AngularJS? -
i new angular js.
is possible forward scope of restaurantcontroller menucontroller code follows
example :-
angular.module('restaurants').controller('restaurantcontroller', ['$scope', function($scope) { $scope.restaurantid="435scvcxvbrcvbnvn"; } ]);
and assigned restaurant id new scope in menu controller follows
angular.module('menus').controller('menucontroller', ['$scope', function($scope) { $scope.currentrestaurantid= $scope.restaurantid; alert($scope.currentrestaurantid); // showing null } ]);
the restaurant id not persisted .. feel thing missing .
how id restaurant controller menu controller ?
try inheritance
angular.module('restaurants', []); angular.module('menus', ['restaurants']); angular.module('restaurants').controller('restaurantcontroller', function($scope) { $scope.restaurantid="435scvcxvbrcvbnvn"; }); angular.module('menus').controller('menucontroller', ['$scope','$controller', function($scope, $controller) { $controller('restaurantcontroller', {$scope: $scope}); $scope.currentrestaurantid= $scope.restaurantid; } ]);
working fiddle
Comments
Post a Comment