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>
  • 相关阅读:
    快速构建一个vue项目的开发环境(基础)
    一个vue的简单例子
    webpack基础使用
    程序日志正常,linux进程异常终止,如何查看日志
    mysql多字段排序
    mysql连表
    go网络
    go通道关闭
    【软考】CMMI的5个等级和22个过程域
    maven工程导入时解决Cannot change version of project facet Dynamic Web Module to 2.3
  • 原文地址:https://www.cnblogs.com/jzm17173/p/4939878.html
Copyright © 2011-2022 走看看