- templateUrl: 加载模板所要使用的 URL。
- 可以加载当前模板内对应的 text/ng-template script id。
- 在使用 chrome 浏览器时,“同源策略”会阻止 chorme 从 file:// 中加载模板,并显示一个“ Access-Control-Allow-Origin ”不允许源为 null,可以把项目放在服务器上加载,或者给 chorme 设置一个标志位,命令为:chorme-allow-file-access-from-files。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div ng-app="myApp"> <script type="text/ng-template" id="customTags2"> <div> hello {{name}} </div> </script> <div ng-controller="firstController"> <custom-tags></custom-tags> <custom-tags2></custom-tags2> </div> </div> <script type="text/javascript" src="../../vendor/angular/angularjs.js"></script> <script type="text/javascript" src="app/index.js"></script> </body> </html>
<div>{{name}}</div>
var myApp = angular.module('myApp',[]) .directive('customTags',function () { return{ restrict: 'ECAM', templateUrl:'tmp/other.html', replace: true } }) .directive('customTags2',function () { return{ restrict: 'ECAM', templateUrl:'customTags2', replace: true } }) .controller('firstController',['$scope',function ($scope) { $scope.name = 'Alrale'; }]);