Home > front end >  Syntax wrong for onclick event on string template
Syntax wrong for onclick event on string template

Time:12-20

The onclick event on the return template doesn't do anything

{
    field: '',
    title: '',
    width: '80px',
    template: function (record) {
        return (
            '  <a href="javascript:void(0);"   ng- ng-click="console.log(record)"> <span>Add</span> </a>'
        );
    }
},

Tried changing the string of the a tag, still unable to call ng-click method.

CodePudding user response:

You have "javascript:void(0)" which is a function in JavaScript that returns undefined. When you click it it wont do anything. Just change href="#" Also update the ng-click to prevent default:

href="#" ng-click="$event.preventDefault();console.log(record)"

For more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void

  • Related