$templateCache スクリプト タグを使用して、HTML ビューを表示します。現在私は、
<body ng-app="myApp">
<div ng-controller="myAppController">
....
....
<div class="col-xs-12">
<my-settings></my-settings>
</div>
..
..
</div>
そして私のapp.js、
var myApp = angular.module('myApp', ['editor']);
myApp.config(['$httpProvider', function($httpProvider) {
....
....
}]);
myApp.controller('myAppController', ['$scope', '$http', '$rootScope', function ($scope, $http,$rootScope) {
//Other stuff
}
ディレクティブ.js
'use strict';
angular.module('editor').directive("my-settings", function() {
return {
templateUrl: '/views/templateId.html'
};
});
script タグを介して、またはサービスとして $templateCache を使用したいのですが、サービスを介してこれを追加する際に、すべての html 要素を $templateCache.put() に配置する必要があります。
var myApp = angular.module('myApp', []);
myApp.run(function($templateCache) {
$templateCache.put('templateId.html', 'This is the content of the template');
});
今思うと、代わりに script タグを使用します。
<script type="text/ng-template" id="templateId.html">
<p>This is the content of the template</p>
</script>
ドキュメントによると、これは $rootElement の子孫である必要があります。<body ng-app="myApp">
では、どこにスクリプトを配置する必要がありますか?これは同じファイル自体に含まれますか?