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
你确定已经包含角文字吗? –