angular.js - About the problem of calling and using global variables after defining them in angularjs
黄舟
黄舟 2017-05-15 17:00:20
0
1
637

The following is the method I found to define global variables (please point out if there is any misunderstanding):
1,myApp.run(function($rootScope) {

$rootScope.haha = 'test';

});

2.<p ng-app="myApp" ng-init="haha='test';">

3.app.value(key, value)

4.app.constant(key, value)

I found that there are only 1 and 2. I can directly output it in the template: {{haha}}, but I don’t know how to call it in the controller?
Then 3 and 4, I can’t output them in the template, let alone in the controller.

Thank you!

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
给我你的怀抱

1

app.controller('controller', function($scope, $rootScope) {
    $scope.haha = $rootScope.haha
})

3/4
http://hellobug.github.io/blog/angularjs...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template