zoukankan      html  css  js  c++  java
  • 指令 作用域

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <div ng-app="myApp" ng-init="someProperty = 'some data'">
            <div ng-init="siblingProperty='moredata'">
                Inside Div Two: {{ aThirdProperty }}
                <div ng-init="aThirdProperty = 'data for 3rd property'" ng-controller="SomeController">
                    Inside Div Three: {{ aThirdProperty }}
                    <div ng-controller="SecondController">
                        Inside Div Four: <span ng-bind="aThirdProperty"></span>
                        <br>
                        Outside myDirective: {{ myProperty }}
                        <div my-directive ng-init="myProperty = 'wow, this is cool'">
                            Inside myDirective: {{ myProperty }}
                        </div>
                    </div>
                </div>
            </div>
            <div ng-controller="aaa">
                $scope.j2
                $scope.j1
                {{j2}}
                {{j1}}
                <div ng-init="j2='j2'">
                    <div ng-init="j1='j1'"></div>
                </div>
            </div>
    
    
            <h1>隔离作用域</h1>
            <p>创建具有隔离作用域的指令需要将scope属性设置为一个空对象{}。如果这样做了,指令的模板就无法访问外部作用域了</p>
            <div ng-controller='MainController'>
                Outside myDirective: {{ myProperty }}
                <div my-directive2 ng-init="myProperty = 'wow, this is cool'">
                    Inside myDirective: {{ myProperty }}
                </div>
            </div>
        </div>
    
        <script src="angular.min.js"></script>
        <script>
            angular.module('myApp', []).controller('SomeController', function($scope) {
            })
            .controller('SecondController', function($scope) {
            })
            .directive('myDirective', function() {
                return {
                    restrict: 'A',
                    scope: true
                }
            })
            .controller('aaa', function($scope) {
            })
            .controller('MainController', function($scope) {
            })
            .directive('myDirective2', function() {
                return {
                    restrict: 'A',
                    scope: {},
                    priority: 100,
                    template: '<div>Inside myDirective {{ myProperty }}</div>'
                };
            });
        </script>
    </body>
    </html>
  • 相关阅读:
    算法题目积累0721
    java编辑器
    java简易编辑器
    公选网站作业4_2.php
    php注册登录系统(一)-极简
    Tomcat与Web服务器、应用服务器的关系
    PHP用户登录与注册页面
    网站选修课作业(4.1)
    网站选修课作业(3.1)
    svn和ftp的区别
  • 原文地址:https://www.cnblogs.com/jzm17173/p/4939878.html
Copyright © 2011-2022 走看看