zoukankan      html  css  js  c++  java
  • Angular 学习笔记——自定义标签

    <!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('myTab',function(){
        return {
            restrict : 'E',   
            replace : true,
            //scope : true,
            scope : {
                myId : '@',
                myName : '=',
                myFn : '&'
            },
            controller : ['$scope',function($scope){
                $scope.name = 'miaov';
            }],
            templateUrl : 'temp2.html'
        };
    });
    
    m1.controller('Aaa',['$scope',function($scope){
        
        $scope.name = 'hello';
        $scope.show = function(n){
            alert(n);
        };
        
    }]);
    
    
    </script>
    </head>
    
    <body ng-controller="Aaa">
    <my-tab my-id="div1" my-name="name" my-fn="show(num)"></my-tab>
    <my-tab my-id="div2" my-name="name" my-fn="show(num)"></my-tab>
    </body>
    </html>

    temp2.html

    <div id="{{myId}}">
        <input class="active" type="button" value="1" ng-click="myFn({num:456})">
        <input type="button" value="2">
        <input type="button" value="3">
        <div style="display:block">{{name}}</div>
        <div>22222222</div>
        <div>33333333</div>
    </div>
  • 相关阅读:
    给窗体加个圣诞帽——抛砖引玉
    《高手寂寞》随感
    离职日记-计划与变化
    什么样的生活
    这一年……
    写在2011第一天的工作前
    Visual C++ 学习笔记四 —— 模板
    bugfree安装与配置
    QTP环境变量的使用
    测试提问单[转]
  • 原文地址:https://www.cnblogs.com/mayufo/p/5008957.html
Copyright © 2011-2022 走看看