有Angular.js這個問題,我似乎無法修復。 這裏是我的簡單html
:Angularjs - 變量未找到
<html ng-app="myAngularapp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script src="myangular.js"></script>
</head>
<body>
<div ng-controller="myAngularCtrl">
<form ng-submit="addingName()">
<input type="text" ng-model="myAngular.newname" size="30"
placeholder="add new todo here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
</body>
</html>
和myangular.js
:
angular.module("myAngularapp",[])
.controller("myAngularCtrl", function($scope){
$scope.myNames = [
{name:"aaa"},
{name:"aaa"},
{name:"aaa"}
];
$scope.addingName = function(){
$scope.myNames.push({name:newname});
}
});
當我按下提交按鈕,我得到了一個錯誤:
Error: Can't find variable: newname
出了什麼問題?
嗨,什麼是** myAngular **。你的意思是代表你的控制器嗎? –