当在相同的Scope函数中使用时,Scope变量返回未定义的值。
的index.html
<body ng-app="starter" ng-controller="AppCtrl">
<form ng-submit="submit()">
<span class="input-label">name</span>
<input type="text" name="name" ng-model="name">
<input type="submit" name="submit" value="Submit">
</form>
</body>
app.js
angular.module('starter', [])
.controller('AppCtrl', function($scope) {
$scope.submit = function(){
alert($scope.name+' scope variable');
}});
输出:
undefined scope variable
将ngModel作为参数传递给ngSubmit的submit()或初始化控制器内的$ scope.name –
我测试了你的代码,它工作的很好.http://jsfiddle.net/Lvc0u55v/13278/ – Ved
@Ved说的都是没问题,你的代码.....但我不能看到关闭}你的函数提交,并有一个额外的)在你的app.js.这可能会导致您的问题 –