信息没有'点击AngularJS中的链接后不会刷新.I'我得到了{{value}},但没有得到数据
Information doesn't refresh after clicking on link in AngularJS. I've got {{ value }} but not the data
我有一个Angular应用程序,它从一些JSON文件中获取信息。第一个JSON文件包含有关城市和管理者的数据。像这样:
[
{
"link" : "veliky_novgorod",
"city" : "Великий Новгород",
"manager" : "mr. Sminth",
},
{
"link" : "magnitogorsk",
"city" : "Магнитогорск",
"manager" : "mr. Young",
},...
我使用它是为了为每个城市创建一个页面。我的URL如下:...index.html#/cities/veliky_novgorod/
、...index.html#/cities/biisk/
、...index.html#/cities/biisk/mobile/
等。
一切都很好,但当我尝试从一个页面转到另一个页面时,来自其他JSON(作用域)的信息不会加载。换页后我总是收到{{ value }}
但当我手动刷新时,一切都会恢复正常。换句话说,单击链接后如何重新加载新页面。我试着用window.location.reload()
,但它不起作用。
<li ng-repeat="city in cities">
<a href="#/cities/{{city.link}}" ng-click="reloadRoute()">{{city.manager}}</a>
</li>
下面是我的模块和控制器:
var curryApp = angular.module('CurryApp', [
'ngRoute',
'curryControllers'
]);
curryApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'link_list.html',
controller: 'CurryListCtrl'
}).
when('/cities/:cityId/', {
templateUrl: 'template-total.html',
controller: 'CurryDetailCtrl'
}).
when('/cities/:cityId/mobile/', {
templateUrl: 'template-mobile.html',
controller: 'CurryMobileCtrl'
}).
otherwise({
redirectTo: '/'
});
}]);
那是我的控制器:
var curryControllers = angular.module('curryControllers', []);
curryControllers.controller('CurryListCtrl', ['$scope', '$http', function($scope, $http) {
$http.get('cities.json').success(function(data) {
$scope.cities = data;
});
}]);
curryControllers.controller('CurryDetailCtrl', ['$scope', '$routeParams', '$http', '$route',
function($scope, $routeParams, $http, $route) {
$scope.reloadRoute = function(){window.location.reload();}
$scope.cityId = $routeParams.cityId;
$http.get('cities.json').success(function(data) {
$scope.cities = data;
$http.get('paidbc.json').success(function(data2) {
$scope.paidBc = data2;
$scope.isActive = function(item) {
return item.link === $scope.cityId;
};
});
});
}]);
curryControllers.controller('CurryMobileCtrl', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.cityId = $routeParams.cityId;
}]);
这似乎是一个与href
属性有关的错误。根据文件:
错误的书写方式:
<a href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
正确的书写方式:
<a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
在您的情况下,使用:
<a ng-href="#/cities/{{city.link}}" ng-click="reloadRoute()">{{city.manager}}</a>
而不是仅使用CCD_ 7。
相关文章:
- 用程序搜索JQuery数据表中的文本
- 要求输入在数据列表中
- 正在将数据主题添加到所有项目
- 函数参数中的数据与指定变量之间的任何性能差异
- 显示多个具有相同源javascript(map(key,value))数据的图表
- 信息没有'点击AngularJS中的链接后不会刷新.I'我得到了{{value}},但没有得到数据
- 使用 orderByChild(“column”), equalTo(“value”),不返回任何数据
- 在将数据呈现为类型化建议之前,使用{{value}}上的函数
- 如何将数据传递给输入VALUE
- 获取value中的数据属性
- AngularJs指令:value from cookie不适用于数据绑定
- 提交时,JSON数据返回:"Cannot read property 'value'undef
- 数据表传递一个带有key:value对象的js数组
- 使用value从JSON对象中获取数据
- 数据搜索innerHTML而不是value
- ng-options中的Value属性不是正确的数据类型
- 从Cloudant获取所有文档数据,而不是id, key, value
- 如何从这个数据结构中推送和弹出值:var x = [{value: 30, color: "red"
- 如何在我的href = "Home/CompletedGrid发送数据?Value = ?????"
- 如何使用变量设置 AJAX 数据$key和$value