0

这大致基于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(...)

4

1 回答 1

1

玉模板的最终输出是什么样的?没有使用过玉,但可能ng-click没有正确转换为 html,因为它不是标准属性。控制台中还有任何错误吗?我也会尝试ng-click="alert('the click handler works')"尝试隔离问题。

于 2013-07-26T06:18:41.817 回答