AngularJS click指令不会触发带Jade的函数

时间:2013-07-26 05:55:29

标签: javascript node.js angularjs pug

这基于MEAN Stack demo:Mongo,Express,AngularJS和NodeJS

我想在我的Jade模板中向我的控制器添加delete方法,如此

characters.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的{​​{1}}因为ng-click函数没有触发,即使它在`ng-controller =“CharactersController”div中?

1 个答案:

答案 0 :(得分:1)

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