0

I am trying set a variable's value inside ng click which is not working.

<a href="#newpage" ng-click="service.name='{{sub.cid}}'"> view</a>

But when i use plain text instead of angular data value it works fine.

<a href="#newpage" ng-click="service.name='abc'">

What is wrong in my code ?

3
  • in link probably use stop.propagation(); Commented May 30, 2017 at 14:04
  • what the benefit of using thsi ? Commented May 30, 2017 at 14:14
  • event.stopPropagation():Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. Commented May 30, 2017 at 14:16

2 Answers 2

1

Remove string interpolation and directly use sub.cid

<a href="#newpage" ng-click="service.name=sub.cid"> view</a>
Sign up to request clarification or add additional context in comments.

Comments

1

Create a function and set values there. Remove logic from template

<a href="#newpage" ng-click="changeValue(sub.cid)"> view</a>
<a href="#newpage" ng-click="changeValue('abc')"> view</a>


function changeValue(val) {
  ctrl.service.name = val;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.