AngularJS click directive doesn't trigger function w/ Jade

Question!

This is loosely based on the MEAN Stack demo: Mongo, Express, AngularJS, and NodeJS

I want to add a delete method to my controller in my Jade template like so

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`

I believe I'm just screwing up the scope of the ng-click as the delete(...) function isn't triggering even though it's within the `ng-controller="CharactersController" div?



Answers

What does the final output of the jade template look like? Haven't used jade but maybe the ng-click isn't converted to html correctly since it's not a standard attribute. Also any errors in the console? I would also try ng-click="alert('the click handler works')" to try and isolate the issue.



This video can help you solving your question :)
By: admin