abhinsit
abhinsit

Reputation: 3272

unable to get value of a variable inside a string : angularjs

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 ?

Upvotes: 1

Views: 48

Answers (2)

abhinsit
abhinsit

Reputation: 3272

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

Upvotes: 0

devqon
devqon

Reputation: 13997

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 }}"

Upvotes: 1

Related Questions