我正在使用 AngularJS 1.5.0
这是我的 HTML:
<!DOCTYPE html>
<html ng-app="app">
<head>
</head>
<body ng-controller="TestController as controller">
{{controller.test}}
<script src="libraries/angular/angular.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
这是我的 app.js:
var app = angular.module("app", []);
app.controller("TestController", function() {
var test = "Hello World";
// window.alert(test); THIS ALERT IS WORKING
});
在我的索引中,它没有显示任何内容。但是,警告测试变量确实有效。
最佳答案
test
变量是您的 Controller 私有(private)的。将其分配给 Controller 实例:
this.test = 'Whatever';
关于javascript - AngularJS - Controller 值不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35645757/