AngularJS ng-click function with Angular Expression parameter returning a Syntax Error

ChanX

I am making a notes web app where I am using AngularJS framework.. I am succesfully displaying notes and I want to delete and update the notes using Unique_id .. I tried doing the ng-repeat with the notes uid in a font-awesome close icon using the a function on click

Code is below:

<div class="bodyContainer">
    <div class="title">
        <h3>Notes<i ng-click="updateFunc()" class="fa fa-refresh"></i></h3>
    </div>
    <div class="notesBox">
        <div class="notes" ng-repeat="Notes in txtArray | limitTo: 5">
            <remove-notes></remove-notes>
            <p class="notesTitle">{{Notes.notes_title}}</p>
            <p>{{Notes.notes_text}}</p>
        </div>
        <h3 class="emptyBox" ng-hide="txtArray.length > 0">Write Your First Note!!</h3>
    </div>
    <div class="homePaging"><a href="#notes">See more</a></div>
</div>

Here is the Directive Code for the <remove-notes> directive:

diary.directive('removeNotes', function () {
return {
    restrict: 'E',
    template: '<i  class="fa fa-close fa-fw" ng-click="removeNote({{Notes.notes_uid}})">',
    link: function ($scope,element,attrs) {
        element.bind('click', function () {
            element.css('color','#19B5FE');
        })
    }
}
});

But When I click the Icon with the click event handler it gives me a parse error:

Error

When I check the Elements panel in the console.. It renders the value of the ang expression {{Notes.notes_uid}}

Is there any better way to implement the delete capability.. I just want to know how to pass the notes_uid to my backend php code in an Async way..

Rebornix

As you are using Angular's built in directive ng-click, you need to remove brackets in your expression.

template: '<i  class="fa fa-close fa-fw" ng-click="removeNote(Notes.notes_uid)">'

Another sample for better understanding: ng-value="myValue" and value="{{myValue}}" are totally the same, but you should't mix them up.

Update

It seems object Notes is not passed to the scope of directive. A possible solution is binding ng-model to directive like

diary.directive('removeNotes', function () {
return {
    restrict: 'E',
    scope: {
      note:'=ngModel'
     //bindAttr: '='
    },
    template: '<i  class="fa fa-close fa-fw" ng-click="removeNote(note.notes_uid)">',
    link: function ($scope,element,attrs) {
        element.bind('click', function () {
            element.css('color','#19B5FE');
        })
    }
}
});

Then in your view outside, bind models to ng-model like

<remove-notes ng-model="Notes"></remove-notes>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJS expression throwing a Syntax error in ng-click

From Dev

AngularJS throwing syntax parse error when using expression as a parameter of a function

From Dev

Angular ng-click giving Syntax Error: Token '{' invalid key at column 22 of the expression

From Dev

AngularJS ng-click: how to call a function with a function as parameter?

From Dev

Getting Syntax Error inside ng-click of a button in angularjs

From Dev

Getting Syntax Error inside ng-click of a button in angularjs

From Dev

Angularjs passing parameter values in ng-click function

From Dev

Can you pass an angular expression as the actual ng-click function

From Dev

ng-click gives "href undefined " error on a function call with a parameter

From Dev

angularjs - ng-class - [$parse:syntax] Syntax Error: Token ':' is an unexpected token at column 11 of the expression

From Dev

AngularJS returning undefined on first ng-click

From Dev

Storing a function expression inside a link function of an angularjs directive and use it via ng-click

From Dev

JS multiple expression in ng-click AngularJS

From Dev

ternary expression in ng-click in angularjs

From Dev

Angularjs expression in ng-click not working in android

From Dev

AngularJs : Passing parameter to ng-click in directive

From Dev

JavaScript Function Parameter - Syntax Error

From Dev

syntax error with ng-click and passing arguments

From Dev

Angular, the result of the expression {{}} is not inserted in ng-click

From Dev

AngularJS function returning promise with required parameter

From Dev

angularjs syntax error with ng-class

From Dev

Expression as parameter inside angular on-click method

From Dev

Function call is returning MySQL Syntax Error 1064

From Dev

Function parameter the same in button ng-click

From Dev

AngularJS ng-class expression throwing error

From Dev

Angularjs - ng-click function vs directive

From Dev

AngularJS ng-click not calling function on scope

From Dev

AngularJS ng-click and callback function

From Dev

AngularJS ng-click not calling function on scope

Related Related

  1. 1

    AngularJS expression throwing a Syntax error in ng-click

  2. 2

    AngularJS throwing syntax parse error when using expression as a parameter of a function

  3. 3

    Angular ng-click giving Syntax Error: Token '{' invalid key at column 22 of the expression

  4. 4

    AngularJS ng-click: how to call a function with a function as parameter?

  5. 5

    Getting Syntax Error inside ng-click of a button in angularjs

  6. 6

    Getting Syntax Error inside ng-click of a button in angularjs

  7. 7

    Angularjs passing parameter values in ng-click function

  8. 8

    Can you pass an angular expression as the actual ng-click function

  9. 9

    ng-click gives "href undefined " error on a function call with a parameter

  10. 10

    angularjs - ng-class - [$parse:syntax] Syntax Error: Token ':' is an unexpected token at column 11 of the expression

  11. 11

    AngularJS returning undefined on first ng-click

  12. 12

    Storing a function expression inside a link function of an angularjs directive and use it via ng-click

  13. 13

    JS multiple expression in ng-click AngularJS

  14. 14

    ternary expression in ng-click in angularjs

  15. 15

    Angularjs expression in ng-click not working in android

  16. 16

    AngularJs : Passing parameter to ng-click in directive

  17. 17

    JavaScript Function Parameter - Syntax Error

  18. 18

    syntax error with ng-click and passing arguments

  19. 19

    Angular, the result of the expression {{}} is not inserted in ng-click

  20. 20

    AngularJS function returning promise with required parameter

  21. 21

    angularjs syntax error with ng-class

  22. 22

    Expression as parameter inside angular on-click method

  23. 23

    Function call is returning MySQL Syntax Error 1064

  24. 24

    Function parameter the same in button ng-click

  25. 25

    AngularJS ng-class expression throwing error

  26. 26

    Angularjs - ng-click function vs directive

  27. 27

    AngularJS ng-click not calling function on scope

  28. 28

    AngularJS ng-click and callback function

  29. 29

    AngularJS ng-click not calling function on scope

HotTag

Archive