Answer the question
In order to leave comments, you need to log in
How to use $scope outside of controller?
I am learning angularjs, and I got up on such a seemingly banal thing:
Here I have a siteContent module, I declare it like this:
<!DOCTYPE html>
<html lang="ru" ng-app="siteContent">
<head >
....
</head>
<body>
<ng-view></ng-view>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Get yourself some kind of service, for example Page, which will contain all the information related to the page in general, such as the current menu item, title, and so on.
app.service('Page', [function () {
var Page = this;
}]);
app.run(['$rootScope', 'Page', function ($rootScope, Page) {
$rootScope.Page = Page;
}])
app.controller('MyCtrl', ['$scope', 'Page', function ($scope, Page) {
Page.myVar = 'lol';
}])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question