私はui-routerを使用していますが、動作していません。ここに私のコードは次のとおりです。私のindex.htmlでui-routerを使用したAngularJSでのルーティング
<li> <a ui-sref="day2">Day 2</a> </li>
<li><a ui-sref="day3">Day 3</a></li>
<li><a ui-sref="day4">Day 4</a></li>
マイmain.js
var myModule = angular.module('myApp', ['ngMessages', 'ui.router']);
myModule.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/day1");
$stateProvider
.state('day1', {
url: '/day1',
templateUrl: 'index.html'
})
.state('day1.example', {
url: '/theview',
template: '<h3>I am a routed view</h3>'
})
.state('day2', {
url: '/day2',
views: {
// the main template will be placed here (relatively named)
'': {
templateUrl: 'day2.html'
}
}
})
.state('day3', {
url: '/day3',
views: {
// the main template will be placed here (relatively named)
'': {
templateUrl: 'day3.html'
},
// the child views will be defined here (absolutely named)
'[email protected]': {
templateUrl: 'directives.html'
},
// for column two, we'll define a separate controller
'[email protected]': {
templateUrl: 'service.html'
}
}
})
.state('day4', {
url: '/day4',
views: {
'': {
templateUrl: 'day3.html'
}
}
});
});
私はそのブラウザでリンクの2日目、3日目と4日目にクリックすると、働いていない。でもday1.exampleがまだ動作していない私は、問題が何であるかわからない
<div>
<a ui-sref=".example" class="save button">Example</a>
</div>
<div ui-view> </div>
</div>
私のindex.htmlの中でこのようにそれを求めています。私はすでにui-routerミニファイルをダウンロードしているので、問題はありません。実際にはブラウザのday1ルートを検出しています 私はscotchチュートリアルに従っていました。
私の問題はtemplateUrl: 'day2.html
に変更するとtemplate: '<h1> Check if it Works </h1>
に変更され、2日目のリンクがうまく機能します。
は 'index.html'を使用する状態テンプレートを設定しないでください。 – Phil