下面是我尝试实现 Controller 的非常简单的示例。
{{8/2}} 给出了正确的输出,即 4
但 {{message}} 保持不变。
它应该被一些值代替,例如第一个 Controller
我从 https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js
下载了 angular js
HTML
<!DOCTYPE html>
<html ng-app>
<head>
<script src="angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<h1>{{8/2}}</h1>
<div ng-controller="HomeController">
{{message}}
</div>
</body>
</html>
脚本.js
var HomeController = function($scope) {
$scope.message = "First Controller";
};
最佳答案
I downloaded the angular js from https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js
嗯,angularjs 版本 1.4x 不支持将原始函数 Controller 用作 Controller 。将 angularjs 版本更改为 1.2.x 或使用 angular.module('someName').controller()
语法使其工作。
这里也是plunkr你分享了(使用 angularjs 1.2.8)
这是 plnkr使用 angular.module() 语法
关于javascript - Angular Js : {{message}} is not replaced by some text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31407300/