<!DOCTYPE html>
<html >
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body ng-app="notePad" ng-controller="notePadCtrl">
<textarea ng-model="message"></textarea>
<button ng-click="save()">save</button>
<button ng-click="clear()">clear</button>
<script src="notePad.js"></script>
<script src="notePadCtrl.js"></script>
</body>
</html>
var app = angular.module("notePad", [] );
app.controller("notePadCtrl",function($scope){
$scope.message="";
$scope.left=function(){
return 100 - $scope.message.lenght;
};
$scope.clear=function(){
$scope.message="";
};
$scope.save=function(){
alert("file got saved");
};
)};
答案 0 :(得分:2)
这是一个错误!替换最后一行。
将)};
替换为});
答案 1 :(得分:-2)
此代码中存在几个问题。首先应该改变控制器支架的关闭
app.controller("notePadCtrl",function($scope){
$scope.message="";
$scope.left=function(){
return 100 - $scope.message.lenght;
};
$scope.clear=function(){
$scope.message="";
};
$scope.save=function(){
alert("file got saved");
};
});
然后在body或head标签内添加angular script标签
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@1.5.8" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="notePad" ng-controller="notePadCtrl">
<textarea ng-model="message"></textarea>
<button ng-click="save()">save</button>
<button ng-click="clear()">clear</button>
</body>
</html>
查看pluker