gpt4 book ai didi

javascript - 单击 AngularJS 中的链接后,信息不会刷新。我有 {{ value }} 但没有数据

转载 作者:行者123 更新时间:2023-11-27 23:05:26 25 4
gpt4 key购买 nike

我有一个 Angular 应用程序,它从几个 JSON 文件中获取信息。第一个 JSON 文件包含有关城市和管理者的数据。像这样:

[
{
"link" : "veliky_novgorod",
"city" : "Великий Новгород",
"manager" : "mr. Sminth",
},
{
"link" : "magnitogorsk",
"city" : "Магнитогорск",
"manager" : "mr. Young",
},...

我用它来为每个城市创建一个页面。我的网址如下所示:...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>

我的模块和 Controller 如下:

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: '/'
});
}]);

这是我的 Controller :

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 属性相关的错误。根据docs :

The wrong way to write it:

<a href="http://www.gravatar.com/avatar/{{hash}}">link1</a>

The correct way to write it:

<a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a>

根据您的情况,请使用:

<a ng-href="#/cities/{{city.link}}" ng-click="reloadRoute()">{{city.manager}}</a>

而不是仅使用href

关于javascript - 单击 AngularJS 中的链接后,信息不会刷新。我有 {{ value }} 但没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36644095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com