zoukankan      html  css  js  c++  java
  • Angular 学习笔记——自定义指令之间的交互

    <!DOCTYPE html>
    <html lang="en" ng-app="myApp">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script type="text/javascript" src="jquery-1.11.1.js"></script>
        <script src="angular.min.js"></script>
        <script type="text/javascript">
            var m1 = angular.module('myApp',[]);
            m1.directive('hi',function(){
                return {
                    restrict:'AE',
                    replace:'true',
                    transclude:'true',
                    template:'<div><h1 ng-transclude></h1></div>'
                }
            });
    
            m1.directive('hello',function (){
                return{
                    restrict:'AE',
                    template:'<span>title</span>'
                }
            })
        </script>
    </head>
    <body>
        <hi>
            <hello></hello>
        </hi>
    </body>
    </html>
    <!DOCTYPE HTML>
    <html ng-app="myApp">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    #div1 div,#div2 div{ 200px; height:200px; border:1px red solid; display:none;}
    #div1 input.active , #div2 input.active{ background:red;}
    </style>
    <script src="angular.min.js"></script>
    <script>
    
    var m1 = angular.module('myApp',[]);
    m1.directive('hello',function(){
        return {
            restrict : 'E',   
            replace : true,
            transclude : true,
            controller : function($scope){
                //$scope.name = 'miaov';
                this.name = 'miaov';
                this.show = function(){};
            },
            template : '<div>hello angular<h1 ng-transclude></h1></div>'
        };
    });
    m1.directive('hi',function(){
        return {
            restrict : 'E',   
            replace : true,
            require : '?^hello', 
            template : '<span>hi angular</span>',
            link : function(scope,element,attr,reController){
                console.log( reController );
            }
        };
    });
    
    m1.controller('Aaa',['$scope',function($scope){
        
    }]);
    
    
    </script>
    </head>
    
    <body ng-controller="Aaa">
    <hello>
        <hi></hi>
    </hello>
    </body>
    </html>
  • 相关阅读:
    发布spring cloud + vue项目
    以太坊上发行ERC20代币
    [转]大白话讲解Promise(一)
    比特币测试网络搭建
    非对称加密, 助记词, PIN, WIF
    搭建EOS未完
    [转]EOS智能合约 & 私链激活 & 基本操作
    [转]https://www.jianshu.com/p/06443248f4d8
    web3js 进行转账
    [转]How to Send Ethereum with Web3.js and Node
  • 原文地址:https://www.cnblogs.com/mayufo/p/5026719.html
Copyright © 2011-2022 走看看