这是一个片段:
<!document html>
<html ng-app>
<head>
<title>First</title>
<script src="D:\Coding\angular.min.js" type="text/javascript"></script>
</head>
<body>
<div ng-controller="FirstController">
<input id="Text1" type="text" ng-model="user.name" />
<div>{{user.name}}</div>
</div>
<script>
function FirstController($scope){
$scope.user = {name: ""};
};
</script>
</body>
</html>
使用Chrome打开.html文件,屏幕上显示“{{user.name}}”。我认为{{}}位置应与文本框内容相同,有什么不对?
答案 0 :(得分:1)
你需要像这样使用:
<ng-app="Your Module Name ">
在控制器写入
var app=angular.module("your module name (can be anything)",[]).controller("myCtrl", function("your dependencies "){});
希望它能运作
答案 1 :(得分:1)
在ng-app属性中,您需要添加应用名称,例如ng-app =&#34; myApp&#34;
<div ng-app="myApp" ng-controller="myCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
</script>
答案 2 :(得分:0)
答案 3 :(得分:0)
如果你使用1.3以下的角度版本它应该工作
<强>样本强>
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://code.angularjs.org/1.2.3/angular.js"></script>
</head>
<body>
<div ng-controller="FirstController">
<input id="Text1" type="text" ng-model="user.name" />
<div>{{user.name}}</div>
</div>
<script>
function FirstController($scope){
$scope.user = {name: "test"};
};
</script>
</body>
</html>
&#13;