Angular的新功能并试图在书中获取示例以运行。例子是关于$ watch方法。下面的代码工作正常:
<html ng-app>
<head>
<title>StartUp Calculator</title>
</head>
<body>
<form ng-controller='StartUpController'>
Starting: <input ng-change="computeNeeded()" ng-model="funding.startingEstimate" />
Recommendation: {{funding.needed}}
</form>
<script src="Scripts/angular.js"></script>
<script>
function StartUpController($scope) {
$scope.funding = { startingEstimate: 0 };
$scope.computeNeeded = function() {
$scope.funding.needed = $scope.funding.startingEstimate * 10;
};
}
</script>
</body>
</html>
但是,当我添加$表法,简化模板,整个页面失败,出现以下:
没有startingEstimate显示在里面的所有输入元件
的{{funding.needed}}变量被显示为文字串在网页
失败的代码是:
<html ng-app>
<head>
<title>StartUp Calculator</title>
</head>
<body>
<form ng-controller='StartUpController'>
Starting: <input ng-model="funding.startingEstimate" />
Recommendation: {{funding.needed}}
</form>
<script src="Scripts/angular.js"></script>
<script>
function StartUpController($scope) {
$scope.funding = { startingEstimate: 0 };
$scope.$watch('funding.startingEstimate', computeNeeded);
$scope.computeNeeded = function() {
$scope.funding.needed = $scope.funding.startingEstimate * 10;
};
}
</script>
</body>
</html>
不知道是什么导致这种情况发生......需要帮助PLZ :-)
JS控制台错误?你能提供一个jsfiddle吗? btw测试$范围$ watch($ scope.funding.startingEstimate,computeNeeded);' –