Angularjs[26] - 自定义指令(2)(templateUrl 属性)

  • 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';
}]);

 

转载于:https://www.cnblogs.com/bky-1083/p/6359086.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值