繁体   English   中英

angularjs ng-submit不起作用

[英]angularjs ng-submit not working

嘿,我是新的,已经是今天的第二个问题,但我需要帮助,当我尝试将ng-submit放在一个表单中时,其表示属性是不允许的,并且如果你可以帮助我,就不会感到高兴。 如果你能向我解释我什么时候需要宣布一个新的控制器? andd就是这样,非常感谢那些帮助的人

 (function() { var app = angular.module('list', []); app.controller('peopleListCtrl',['$scope', function($scope){ $scope.persons = plists; this.addPerson = function() { if (this.text) { persons.push(this.person); this.text=''; } }; }]); var plists = [ { name: 'alon', job: 'web dev', home:'nir tzvi' }, { name: 'ben', job: 'katbamflighter', home:'nir tzvi' }, { name: 'shiraz', job: 'dentist assistant', home:'hadera west' } ]; })(); 
 <!DOCTYPE html> <html ng-app="list"> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> <script type="text/javascript" src="app.js"> </script> </head> <body ng-controller="peopleListCtrl"> <br /> <div ng-repeat="people in persons"> <h3> {{people.name}} {{people.job}} {{people.home}} </h3> </div> <br /> <form name="personForm" ng-submit="peopleListCtrl.addPerson()" > <input type="text" ng-model="person.name"/> Name:{{person.name}} <br /> <input type="text" ng-model="person.job"/> job:{{person.job}} <br /> <input type="text" ng-model="person.home"/> home:{{person.home}} <br /> <input type="submit" value="submit" /> </form> </body> </html> 

这是演示

 (function() { var app = angular.module('list', []); app.controller('peopleListCtrl',['$scope', function($scope){ var plists = [ { name: 'alon', job: 'web dev', home:'nir tzvi' }, { name: 'ben', job: 'katbamflighter', home:'nir tzvi' }, { name: 'shiraz', job: 'dentist assistant', home:'hadera west' } ]; $scope.persons = plists; $scope.persion = []; $scope.addPerson = function() { if ($scope.person) { $scope.persons.push($scope.person); $scope.person=null; } }; }]); })(); 
 <!DOCTYPE html> <html ng-app="list"> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> <script type="text/javascript" src="app.js"> </script> </head> <body ng-controller="peopleListCtrl"> <br /> <div ng-repeat="people in persons"> <h3> {{people.name}} {{people.job}} {{people.home}} </h3> </div> <br /> <form name="personForm" ng-submit="addPerson()" > <input type="text" ng-model="person.name"/> Name:{{person.name}} <br /> <input type="text" ng-model="person.job"/> job:{{person.job}} <br /> <input type="text" ng-model="person.home"/> home:{{person.home}} <br /> <input type="submit" value="submit" /> </form> </body> </html> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM