在下面的代码中,
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Controller</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular.js"></script>
<script type="text/javascript">
var app = angular.module("sample", []);
app.controller("emp", function(){
this.Name = "jag";
});
</script>
</head>
<body ng-app="sample">
<div ng-controller="emp">
Hello {{Name}}
</div>
</body>
</html>
{{ Name }}
表达式未评估。
1)如何检查$scope
模型是否与视图中的div
模板绑定?
2)我了解到范围位于DOM。使用指令ng-controller="emp"
创建控制器实例。我可以通过DOM访问控制器(emp
)实例和$scope
吗?
答案 0 :(得分:2)
如果您使用
controller as
而不是this
,请使用$scope
。Controllers
classes
为initializing
,var student = new Student()
他们(controller as
)使用var app = angular.module("sample", []); app.controller("emp", function() { this.Name = "jag"; });
语法。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="sample">
<div ng-controller="emp as e">
Hello {{e.Name}}
</div>
</body>
&#13;
function checkForKey(key, json) {
var found = false;
for(var x in json) {
if (json.hasOwnProperty(x)) {
if(json[x][data] == key) {
found = key;
}
}
}
return found;
}
&#13;