我将角度js代码从1.2.26升级到1.3.12,突然数据绑定失败。我以为我跟着1.3风格的控制器。请指教
<!DOCTYPE html>
<html data-ng-app="myApp">
<head>
<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"> </script>
</head>
<body>
<p>Try to change the names.</p>
<div ng-app="" data-ng-controller="PersonController">
First Name: <input type="text" data-ng-model="firstName"><br>
Last Name: <input type="text" data-ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</div>
<script>
var myApp = angular.module('myApp', []).controller('PersonController', [funnction() {
$scope.firstName= "John";
$scope.lastName= "Doe";
}]);
</script>
</body>
</html>
答案 0 :(得分:2)
答案 1 :(得分:0)
Mosho是正确的,我应该删除第二个ng-app。但还有另一个问题。应移除控制器周围的支架对。
<script>
angular.module('myApp', []).controller('PersonController', [function() {
$scope.firstName= "John";
$scope.lastName= "Doe";
}]);
</script>
没有工作。
删除braket后
<script>
angular.module('myApp', []).controller('PersonController', function($scope) {
$scope.firstName= "John";
$scope.lastName= "Doe";
});
</script>
它开始起作用了。我看到1.3
需要括号