私は小さなテンプレートがたくさんあるので、それらを1つのhtmlファイルに入れます。angularJs:ng-include内のng-template
smallTemlates.html
<script type="text/ng-template" id="template1.html">
...
</script>
<script type="text/ng-template" id="template2.html">
...
</script>
それから私はindex.html
内部smallTemlates.html
が含まれます。
index.html
<body ng-app="myapp" id="my-app">
<div ng-include="'pathTo/smallTemlates.html'"></div>
</body>
それから私は$ templateRequestを使用して、私のコントローラ/サービスの内部でこれらのテンプレートにアクセスしようとしましたが、それは404エラーを投げています。
$templateRequest(component.popoverTemplateUrl).then(function(html) {
var template = html // 404 error
});
しかし、私はそれだけで正常に動作を下回るようindex.html
にdirecltyこれらのテンプレートを追加した場合。
<body ng-app="myapp" id="my-app">
<script type="text/ng-template" id="template1.html">
...
</script>
<script type="text/ng-template" id="template2.html">
...
</script>
</body>
'smallTemlates.html'のコンテンツが利用可能かどうかを確認しましたか? –
@DhanaSekarはい利用可能です。 –