问题描述
以下是我找到的定义全局变量的方法(如果有错误理解还请指出):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)
我发现只有1和2,我能在模版中直接输出:{{haha}},但是不知道在controller里如何能调用到呢?然后3和4,我在模版中也输出不了,更不用说在controller里了。
谢谢!
问题解答
回答1:1
app.controller(’controller’, function($scope, $rootScope) { $scope.haha = $rootScope.haha})
3/4http://hellobug.github.io/blog/angularjs...