我有以下(也在Plunker):
<!doctype html>
<html
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
</head>
<body ng-app="theApp">
<div ng-conroller="ExampleCtrl as ctl">
<input type="text" ng-model="ctl.value"/><br>
{{ctl.value}}
</div>
<div ng-controller="ExampleCtrl as ctl">
<input type="text" ng-model="ctl.value"/><br>
{{ctl.value}}
</div>
<script>
angular.module('theApp', [])
.controller('ExampleCtrl', [
function () {
var self = this;
self.value = 'Lorem ipsum';
console.log('controller instantiated');
}
]);
</script>
</body>
</html>
查看控制台,我只看到一条消息controller instantiated
,并且只有第二个收件箱下方打印了绑定值:
我期待两个单独的控制器被实例化,实际上在填充值之后似乎有两个独立的范围,但是我无法解释初始状态。