angularjs笔记
  • Introduction
  • 依赖注入
  • 作用域
  • 数据绑定
    • 控制器->模板->控制器->模板
  • 多个控制器
  • $scope对象
    • $apply方法、$digest方法
    • $watch方法
    • 示例:购物车
  • 模块和控制器
  • $provide对象的provider、factory、service方法
    • 多个控制器内共享数据
  • 过滤器(Filters)
    • number、currency、date
    • limitTo、lowercase、uppercase
    • filter、orderBy、json
    • 示例:产品列表
    • 自定义过滤器
  • 控制器(controller)
    • 显式和隐式依赖注入
  • 指令
    • Angular 内置指令
    • Angular 自定义指令
      • restrict、template、replace属性
      • templateUrl属性
      • transclude、priority、terminal属性
      • compile && link属性
      • controller && controllAs属性
      • require属性
      • scope属性
  • Module里其他方法
    • constant、value、run方法
  • Form表单
    • 示例:注册页
  • XHR和服务器端的通信
    • $http
  • JavaScript基础
    • .isFunction是否为函数
  • 资料链接
  • 功能组件
    • Tooltip
    • CSV
  • 其他
    • $watchCollection
    • $controller 继承
    • 两个对象合并
    • 页面关闭
    • AngularJs 时间格式化处理
    • 数据的本地存储
    • 页面的URL
Powered by GitBook
On this page

Was this helpful?

  1. 指令
  2. Angular 自定义指令

templateUrl属性

  • templateUrl:加载模版所要使用的URL

  • 可以加载当前模板内对应的的text/ng-template script id

  • 在使用chrome浏览器时,"同源策略"会阻止chrome从file://中加载模版,并显示一个"Access-Control-Allow-Origin" 不允许源为null , 可以把项目放在服务器上加载,或者给Chrome设置一个标志,命令为:chrome —allow-file-access-from-files

例子:

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

</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 src="//cdn.bootcss.com/angular.js/1.4.8/angular.js"></script>
<script type="text/javascript" src="app/index.js"></script>


</body>
</html>

app/idnex.js

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 = '张三';
    }]);

tmp/other.html

<div>
    {{name}}
</div>
Previousrestrict、template、replace属性Nexttransclude、priority、terminal属性

Last updated 5 years ago

Was this helpful?