2016-05-26 44 views
1

我無法獲得在以下情況下,一個變量的值:無法得到一個字符串中的變量值:angularjs

的onclick =「window.location.href =「#/應用/ tmnl/{{message.pid}}」「

它只是打印這 '#/應用/ 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> 

任何人都可以告訴我我犯的錯誤嗎?

+1

你已經把它作爲一個字符串: '#/ app/tmnl/{{message.pid}}''。做一些類似'{{#/ app/tmnl /'+ message.pid}}'而不是 – devqon

+0

你可以添加你的控制器代碼嗎? –

回答

1

您已將{{ }}置於一個字符串中,因此角度將不會評估該字符串。做這樣的事情,而不是:

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

感謝您的回覆,但這不起作用:-( – abhinsit

0

它工作時,我取代的onclick到NG-點擊

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

謝謝大家對其他的答案,以及

+0

您不應該使用window.location.href。它將重新加載整個頁面。如果您希望單頁應用程序行爲,這是不正確的。 –

+0

我應該怎麼做然後呢?sref改變? – abhinsit

+0

要麼ng-href或sref是正確的方法。嘗試用我的答案這樣:

相關問題