3
我在某些視圖中使用了AngularJS的Rails應用程序。每當我點擊使我想到一個頁面的鏈接,說/certifications
我看到這個AngularJS和Rails視圖需要頁面刷新
然後,當我重新加載頁面或按要求將其輸入在地址欄,它的工作原理,並顯示此
這兩個頁面是如何被重新加載,這是搞砸AngularJS有什麼區別。我需要用戶和角度路由器嗎?我已經把視圖和控制器的代碼放在下面。謝謝您的幫助!
控制器:
@aquaticsApp = angular.module 'aquaticsApp',
['ngResource', 'aquaticsAppFilters']
@aquaticsApp.controller 'CertsCtrl', ['$scope', 'Certs',
@CertsCtrl = ($scope, Certs) ->
$scope.formatDate = (dateString) ->
d = new Date(dateString)
curr_month = d.getMonth() + 1
curr_date = d.getDate()
curr_year = d.getFullYear()
"#{curr_month}/#{curr_date}/#{curr_year}"
$scope.sorter =
value: 'firstName'
Certs.get (data) ->
$scope.certNames = data.certification_names
$scope.users = data.users
]
查看:
<div ng-app='aquaticsApp' class='table-responsive'>
<table ng-controller='CertsCtrl' class='table table-hover table-condensed'>
<thead>
<tr>
<th ng-click='sorter.value="lastName"'>Last Name</th>
<th ng-click='sorter.value="firstName"'>First Name</th>
<th ng-click='sorter.value="location"'>Location</th>
<th ng-repeat='certName in certNames' ng-click='sorter.value=certName.name'>
{{certName.name}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='userData in users | orderBy:sorter.value'>
<td>{{userData.lastName}}</td>
<td>{{userData.firstName}}</td>
<td>{{userData.location}}</td>
<td ng-repeat='certName in certNames' class='{{userData[certName.name + "class"]}}'>
{{formatDate(userData[certName.name])}}
</td>
</td>
</tr>
</tbody>
</table>
</div>
在角度編譯和鏈接之前需要等待一段時間,然後表達式纔會被替換。代碼對我來說似乎完全合適。您可以嘗試將綁定(雙'{')放在div中以避免在頁面準備好之前顯示它們。 –
它似乎並沒有編譯。表達式會無限期地停留在那裏,並且不會被替換,除非我通過地址欄進行刷新或訪問該頁面。 – kmanzana
你確定已經包含角文字嗎? –