1

I am unable to get the value of a variable in following case :

onclick="window.location.href = '#/app/tmnl/{{ message.pid }}' "

it just prints this to '#/app/tmnl/{{ message.pid }}' instead to taking the value of message.pid

<div ng-repeat="message in userMessages track by $index">
            <a class="item item-avatar" href="#">
                <img src="https://graph.facebook.com/{{ message.a1id }}/picture?type=square">
                <h2>{{ message.mdata.a1n }}</h2>
                <p>Back off, man. I'm a scientist.</p>
                <button class="button button-small button-positive" href="#/app/tmnl/{{ message.pid }}" onclick="window.location.href = '#/app/tmnl/{{ message.pid }}' ">
                    View
                </button>
            </a>
        </div>

Can anyone tell me the mistake i am making ?

2
  • 1
    You have put it as a string: '#/app/tmnl/{{ message.pid }}'. Do something like {{ '#/app/tmnl/' + message.pid }} instead Commented May 26, 2016 at 7:41
  • Can you add your controller code ? Commented May 26, 2016 at 7:57

2 Answers 2

1

You have put the {{ }} in a string, so angular won't evaluate that. Do something like this instead:

onclick="window.location.href = {{ '#/app/tmnl/' + message.pid }}"
Sign up to request clarification or add additional context in comments.

Comments

0

It worked when i replaced onclick to ng-click

ng-click="window.location.href = '#/app/tmnl/{{ message.pid }}' "

Thanks everyone for other answers as well

3 Comments

You should not be using window.location.href. It will reload the entire page. If you want Single page application behavior this is not the right way.
What should i do then? a sref change ?
either ng-href or sref would be the correct way. Try using my answer in this way : <button><a ng-href="#/app/tmnl/message.pid">Button Text</a></button>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.