无法获取字符串中变量的值:angularjs

时间:2016-05-26 07:37:33

标签: javascript angularjs

在以下情况下,我无法获取变量的值:

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

它只是打印到'#/ app / tmnl / {{message.pid}}'而是取值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>

谁能告诉我我犯的错误?

2 个答案:

答案 0 :(得分:1)

你已将{{ }}放在一个字符串中,所以angular不会对此进行评估。做这样的事情:

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

答案 1 :(得分:0)

当我更换onclick到ng-click

时,它有效
ng-click="window.location.href = '#/app/tmnl/{{ message.pid }}' "

感谢大家的其他答案