Hey, I am new and already the second question for today, but I need help when I try to put ng-submit inside the form, its say attribute is not allowed and does not work. If you help me, be happy. and if you can explain to me when do I need to declare a new controller? and it is, thanks a lot for those who help
(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>
Run code
source
share