这大致基于MEAN Stack 演示:Mongo、Express、AngularJS 和 NodeJS
我想像这样delete
在我的 Jade 模板中向我的控制器添加一个方法
字符.jade
script
function CharactersController($scope, $http, $window){
$scope.charactersList = [];
$scope.newCharacter = {};
$scope.init = function(charactersList){
$scope.charactersList = charactersList;
}
$scope.save = function(form){
}
$scope.delete = function(id){
console.log('delete: '+id);
}
}
body
h1 Characters
div(ng-controller="CharactersController", ng-init="init( #{JSON.stringify(charactersList)} );") Create a new character:
br
form(name="charactersForm", ng-submit="save(charactersForm)")
input(type="string", ng-model="newCharacter.firstName", name="firstName", placeholder="Firstname...")
input(type="submit")
hr
div(ng-repeat="character in charactersList.characters")
{{character.lastName}}, {{character.firstName}} - Quantity: {{character.quantity}}
button(ng-click="delete('{{character._id}}')") remove`
我相信我只是搞砸了scope
,因为即使它在 `ng-controller="CharactersController" div中ng-click
,该函数也没有触发?delete(...)