Javascript angularjs-$state.go更改url但不加载html页面
我正在用angularJS练习布线,遇到了一个问题。我上网查了查,尝试了很多方法,但都没有解决我的问题。你能帮我吗 我对$state.go函数有问题。它会更改url,但不会加载html文件。我查看了控制台,但没有出现错误 app.jsJavascript angularjs-$state.go更改url但不加载html页面,javascript,angularjs,routing,angular-ui-router,state.go,Javascript,Angularjs,Routing,Angular Ui Router,State.go,我正在用angularJS练习布线,遇到了一个问题。我上网查了查,尝试了很多方法,但都没有解决我的问题。你能帮我吗 我对$state.go函数有问题。它会更改url,但不会加载html文件。我查看了控制台,但没有出现错误 app.js (function(){ var app = angular.module('myTrello', ['date-directives', 'ngRoute', 'ui.router']); app.controller("mainCt
(function(){
var app = angular.module('myTrello',
['date-directives', 'ngRoute', 'ui.router']);
app.controller("mainCtrl", ['$scope', '$http', '$state', '$route', function($scope, $http, $state, $route){
$scope.title = "Welcome to my trello";
$http.get("http://quotes.rest/qod.json")
.then(function(response) {
let quoteInfo = response.data.contents.quotes[0];
$scope.quote = quoteInfo.quote;
$scope.author = quoteInfo.author;
});
$scope.go = function(path) {
$state.go(path, {});
};
}]);
app.controller("boardCtrl", function(){
});
// app.controller("routeCtrl", function($scope, $routeParams) {
// $scope.param = $routeParams.param;
// });
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'index.html',
controller: 'mainCtrl'
})
.state('boards', {
url: '/boards',
templateUrl: 'boards/board.html',
controller: 'boardCtrl'
})
// .state('/boards/:param', {
// url: '/boards/:param',
// templateUrl: 'index.html',
// //controller: 'boardCtrl'
// })
}]);
})();
index.html(重要部分)
{{title}}
今天的报价
{{quote}}
作者:{{作者}
我的董事会
board.html
<html>
<h1>Boards</h1>
</html>
董事会
当您使用ui路由器时,您需要使用ui-view
指令而不是ng-view
,因此将代码更改为
<div ui-view></div>
而不是
<div ng-view></div>
当您使用ui路由器时,您需要使用ui-view
指令而不是ng-view
,因此将代码更改为
<div ui-view></div>
而不是
<div ng-view></div>