gpt4 book ai didi

angularjs - Ui-sref 不生成可点击的链接/不工作

转载 作者:行者123 更新时间:2023-12-03 16:54:16 25 4
gpt4 key购买 nike

我之前为此使用了 ng-route,它运行良好,但是使用 UI Router,链接不再可点击,或者至少大部分时间都不可点击。当它们是非常随机的时,它们不会显示我正在使用的 html 模板。

HTML:

<head>
<title>Tutorial</title>

<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-ui-router.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>

</head>

<body>

<ng-view></ng-view>

<ul class="menu">
<li><a ui-sref="view1">view1</a></li>
<li><a ui-sref="view2">view2</a></li>
</ul>

.js
angular.module('myApp', [
'myApp.controllers',
'ui.router'
]);

angular.module('myApp').config(function($stateProvider, $urlRouterProvider) {

$stateProvider.state('view1',{
url: '/view1',
controller:'Controller1',
templateUrl:'/view1.html'
}).state('view2', {
url: '/view2/:firstname/:lastname',
controller: 'Controller2',
resolve: {
names: function() {
return ['Misko', 'Vojta', 'Brad'];
}
},
templateUrl: '/view2.html'
});

$urlRouterProvider.otherwise('/view1');

});


angular.module('myApp.controllers', []).controller('Controller1', function($scope, $location, $state) {

$scope.loadView2=function() {
$state.go('view2', {
firstname: $scope.firstname,
lastname: $scope.lastname
});
};
}).controller('Controller2', function($scope, $stateParams, names) {
$scope.firstname = $stateParams.firstname;
$scope.lastname = $stateParams.lastname;
$scope.names = names;

});

我正在按照关于 AngularJS 的 SitePoint 电子书中的说明进行操作,所以我不确定自己做错了什么或错过了什么。

http://plnkr.co/edit/amh3nZmyB7lC2IQi3DIn

最佳答案

我没有看到 ui-view标记中的任何位置,因此您的状态 View 很可能不会被渲染和注入(inject)。

你不应该需要 ng-view .单ui-view应该存在于您的主 HTML 文件中。您的顶级状态将在那里渲染和注入(inject)。状态可以有子状态,每个具有子状态的状态模板都应该有一个 ui-view它自己的渲染子状态将被注入(inject)。

浏览 ui-router 's readme让它工作的基础知识。此外,他们有一个很好的demo app ,它的来源确实帮助我理解了这个状态路由引擎是关于什么以及如何使用它。

关于angularjs - Ui-sref 不生成可点击的链接/不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27594132/

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