Abh*_*hik 3 javascript angularjs angularjs-scope angularjs-controller
我的Javascript
var app = angular.module('Demo', []);
app.controller('DemoCtrl', function ($scope) {
$scope.expr = "Test"
});
app.controller('Test', function ($scope) {
$scope.HELLO = "HEllo World";
});
Run Code Online (Sandbox Code Playgroud)
我的马克
<body ng-controller="DemoCtrl">
<div ng-controller="{{expr}}">{{HELLO}}</div>
</body>
Run Code Online (Sandbox Code Playgroud)
这不起作用.文档说ng-controller可以评估表达式.我做错了什么?
将控制器写为函数(不作为app.controller('Test')
将JS更改为:
var app = angular.module('Demo', []);
app.controller('DemoCtrl', function ($scope) {
$scope.expr = Test;
});
function Test($scope) {
$scope.HELLO = "HEllo World";
}
Run Code Online (Sandbox Code Playgroud)
和HTML:
<body ng-controller="DemoCtrl">
<div ng-controller="expr">{{HELLO}}</div>
</body>
Run Code Online (Sandbox Code Playgroud)
演示 JS BIn
| 归档时间: |
|
| 查看次数: |
2924 次 |
| 最近记录: |