zoukankan      html  css  js  c++  java
  • Directive指令的template配置项使用说明

    template------(字符串或者函数)可选参数


         1.字符串

    <hello-world></hello-world>

    var app = angular.module('myApp', []);
    app.directive('helloWorld', function() {
     return {
        restrict:"EA",
     template: '<div><h1>你好!</h1></div>',
     replace: true//替换
     };
    });

        2.一个函数,可接受两个参数tElement和tAttrs

    其中tElement是指使用此指令的元素,而tAttrs则实例的属性,它是一个由元素上所有的属性组成的集合(对象)形如:
    <hello-world2 title = '我是第二个directive'></hello-world2>  
    其中title就是tattrs上的属性

      <hello-world2 title = '我是第二个directive'></hello-world2

    var myapp=angular.module("app",[]);

    myapp.directive("helloWorld2",function($compile){

      return{

        restrict:"EA",

        template:function(tElement,tAttrs){

          var html="";

          html+="<div>"+tAttrs.title +"</div>";

          return html;

        }

      }

    })

     

     

     

  • 相关阅读:
    PageRank
    Web挖掘
    无监督学习
    Activiti 学习笔记记录(2016-8-31)
    Activiti 学习笔记记录(二)
    Activiti 学习笔记记录
    Mybatis + SpringMVC + Maven实现分页查询
    Jquery.min.js 下载
    使用Apache Archiva搭建Maven Repository Server
    SpringMVC 参数传递
  • 原文地址:https://www.cnblogs.com/yogic/p/8312551.html
Copyright © 2011-2022 走看看