簡體   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