Hans Karlsen (talk | contribs) (Created page with "ng-click is the angular replacement for onclick event. If you try to this in a simple component you get an error since you cannot bind into javascript - only html: ... oncli...") |
Hans Karlsen (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
If you try to this in a simple component you get an error since you cannot bind into javascript - only html: | If you try to this in a simple component you get an error since you cannot bind into javascript - only html: | ||
... onclick="CallFunction(<nowiki>{{data.SomeValue}}</nowiki>)" .... | ... onclick="CallFunction(<nowiki>{{data.SomeValue}}</nowiki>)" .... | ||
If you try | If you try the below code nothing happens - due to your CallFunction is not part of the scope - it is outside the scope: | ||
... ng-click="CallFunction(data.SomeValue)" .... | ... ng-click="CallFunction(data.SomeValue)" .... | ||
The kosher way is to define a directive ( a directive is a definition that enables you to tie html-elements to javascript-scope-data ) | The kosher way is to define a directive ( a directive is a definition that enables you to tie html-elements to javascript-scope-data ) |
Revision as of 10:02, 23 May 2020
ng-click is the angular replacement for onclick event.
If you try to this in a simple component you get an error since you cannot bind into javascript - only html:
... onclick="CallFunction({{data.SomeValue}})" ....
If you try the below code nothing happens - due to your CallFunction is not part of the scope - it is outside the scope:
... ng-click="CallFunction(data.SomeValue)" ....
The kosher way is to define a directive ( a directive is a definition that enables you to tie html-elements to javascript-scope-data )
But if you want to solve with minimum effort I suggest you do this workaround:
...p1="{{data.SomeValue}}" onclick="CallFunction(this.getAttribute('p1'))" ....
What the above code does: we use angular's ability have bindings in html - but we use it in an attribute we defined ourselves. Then we use javascripts ability to access that attributes' value and call our function.