適切なルーティングを確保するには、ui-router を使用できます。
これがプランカーの例です
これがどのように機能するか:
1 - github のインストール ガイドに従ってください
2 - 状態の定義を書きます:
app.config(function($stateProvider, $urlRouterProvider){
//If no route match, you'll go to /index
$urlRouterProvider.otherwise('/index');
//my index state
$stateProvider
.state('index', {
url: '/index',
templateUrl: 'index2.html',
controller: 'IndexCtrl'
})
//the variable state depending on an url element
.state('hello', {
//you will be able to get name with $stateParams.name
url: '/hello/:name',
templateUrl: 'hello.html',
controller: 'HelloCtrl'
})
});
3 - 州名でリンクを書きます :
//add this directive to an html element
//This will go to /index
ui-sref="index"
//This will go to /hello/
ui-sref="hello"
//This will go to /hello/ben
ui-sref="hello({name:'ben'})"
//This will go to /hello/{myname}
ui-sref="hello({name:myname})"
4 - パラメータをコントローラーに取得します。
//inject $stateParams
app.controller('HelloCtrl', function($scope, $stateParams){
$scope.controller = "IndexCtrl";
//get the param name like this
$scope.name = $stateParams.name;
});
それが役に立ったことを願っています。また、ui-router には、resolve やネストされた状態/ビューなどの非常に強力なツールがあることにも注意してください。あなたはおそらく今、または後で論文を必要とするでしょう。
PS : プランカーが機能しない場合は、フォークして再度保存してください。