私は再して、複数のコントローラを許可するディレクティブを使用しますページ1とページ2の間のコードを使用して、次のようになりアンギュラ2.
あなたのページへの移行の準備のために:
<section1></section1>
<section2></section2>
<section3></section3>
<section4></section4>
そして、あなたはセクションごとにディレクティブを記述する必要があります。ここでは
module.directive('section1', function() {
return {
scope: {},
bindToController: {
},
controller: function() { },
controllerAs: 'vm',
template: `
<div>This is section1
</div>
`
}
});
あなたは活字体を使用することに興味がある場合は上記で説明したように、ここでtutorial that includes two pages with 2 shared sections using directivesあるapproximate module in Angular 1.x
に品です。 「共有ディレクティブのあるサンプルページ」という最後の部分を見てください。チュートリアルにはgithub repositoryが含まれています。/
h1 page2
page2-section2
page2-section1
ページ1とページ2の間のコントローラは非常に類似しており、これを用いたセクションタグを作成します。そのチュートリアルで は、Page1のは
h1 page1
page1-section1
page1-section2
のように見え、2ページ目は、同じ部分を共有しました共有ディレクティブ(DigiSection1.Section1Directive):
angular
.module('digiangularjs.page1', [])
.controller('agendaController', Page1Controller)
.directive("page1Section1", [() => new DigiSection1.Section1Directive()])
.directive("page1Section2", [() => new DigiSection2.Section2Directive()])
;
そして、2ページ目のために、私たちは同じディレクティブを使用しますが、
angular
.module('digiangularjs.page2', [])
.controller('page2Controller', Page2Controller)
.directive("page2Section1", [() => new DigiSection1.Section1Directive()])
.directive("page2Section2", [() => new DigiSection2.Section2Directive()])
;
2つの状態(2ページ分)を使用し、異なるビュー(セクション)を使用すると、各ビューはディレクティブになります。 – MayK
通常は推奨されていませんが、ルーティングでページ・コントローラーを定義するのではなく、ngControllerディレクティブを使用することができます。私はそのように行くだろう。 –
@MayK:おかげさまで、2つの州では、両方のページにそれぞれコントローラが1つしかないでしょうか? – Anamadeya