【发布时间】:2016-09-29 20:04:00
【问题描述】:
(学习AngularJS,1.5.5版)
我得到了下面的代码
<form ng-submit="addCust.submit()" ng-controller="AddCustomerCtrl as addCust">
<div> <input type="text" ng-model="addCust.cName" required/> </div>
<div> <input type="text" ng-model="addCust.cCity" required/> </div>
<div> <button id="f1" type="submit" >Add Customer</button> </div>
</form>
controller.js 包含以下代码
helloWorldControllers.controller('AddCustomerCtrl', ['$scope', '$location',
function AddCustomerCtrl($scope, $location) {
$scope.submit = function(){ console.log('AddCustomerCtrl.submit !');
$location.path('/addedCustomer/' + $scope.cName + "/" + $scope.cCity); };
}
]);
如果我避免在 HTML 中为控件设置别名(“AddCustomerCtrl as addCust”),一切都很好
我不知道我错在哪里。欢迎任何帮助。提前致谢!
(...是的!我是 AngularJS 的新手)
胡安
【问题讨论】:
标签: angularjs controller submit aliasing