http://plnkr.co/edit/0W4ATi7loAKk94Cnj3lz?p=preview
一个简单的 Angular 应用程序,不知道为什么ng-submit
没有触发该createMeetup
功能
HTML
<!-- Meetups View -->
<div ng-controller="meetupsController">
<h1>There are {{meetupsCount}} meetups</h1>
<ul>
<li ng-repeat="meetup in meetups">
{{meetup.name}}
</li>
</ul>
</div>
<form ng-submit="createMeetup()">
<input ng-model="meetupName" type="text" placeholder="Meetup name"></input>
<button type="submit">Add</button>
</form>
控制器
var app = angular.module('meetupsApp', [])
.controller('meetupsController', ['$scope', function($scope) {
$scope.meetupsCount = 10;
$scope.meetups = [
{ name: "MEAN SF Developers" },
{ name: "Some other meetup" },
]
$scope.createMeetup = function() {
console.log('clicked');
$scope.meetups.push({ name: $scope.meetupName });
$scope.meetupName = '';
}
}]);