Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AngularJs directive-scope大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

1.scope:bool 或者 object代码

<body ng-app="myApp">
    <div ng-controller="myCtrl">
        外部:{{myProperty}}
        <input  ng-model="myProperty"/>
        <br />
        <div my-directive></div>
    </div>
</body>
var app = angular.module('myApp',[]);
app.controller('myCtrl',function ($scope) {
  $scope.myProperty = '张三';
});
app.directive('myDirective',function () {
  return {
    reStrict: 'A',scope: false,//继承但不隔离,控件内部,外部数据同步
    //scope:true,//继承并隔离,即template内部变量修改,不影响外部
    // scope:{},//隔离且不继承
    template: '<div class="bg-priMary">内部:{{myProperty}} <input class="text-priMary" ng-model="myProperty"/> </div>'
  }
});


2.scope制定object绑定

<body ng-app="myApp">
    <div class="container-fluid">
        <div ng-controller="myCtrl">
            外部:{{myProperty}}
            <br />
            <my-directive title="myProperty"></my-directive>
        </div>
    </div>
</body>
//定义模块,封装指令
angular.module('common',[])
.directive('myDirective',function () {
    return {
        reStrict: 'E',//内部重新定义绑定字段名称
        scope: {
            //title: '@' //将标签定义的字符串,绑定显示
            title:'=' //将指令内部scope字段和指令外部模块scope字段双向绑定
        },template: '<div class="bg-priMary">内部:{{titlE}} <input  class="text-priMary" ng-model="title"/> </div>'
    }
});
//使用指令 myProperty对应外部绑定字段名称title对应指令内部绑定名称
var app = angular.module('myApp',['common']);
app.controller('myCtrl',function ($scope) {
    $scope.myProperty = '张三';
});

3.绑定页面,指定的字符串内容代码
<body ng-app="myApp">
    <div side-Box title="TagCloud">
        <div class="tagcloud">
            <a href="">Graphics</a>
            <a href="">ng</a>
            <a href="">D3</a>
            <a href="">Front-end</a>
            <a href="">Startup</a>
        </div>
    </div>
</body>
angular.module('myApp',[])
    .directive('sideBox',function () {
        return {
            reStrict: 'EA',scope: {
                title: '@'
            },transclude: true,template: '<div class="sideBox"><div class="content"><h2 class="header">' +
                '{{ title }}</h2><span class="content" ng-transclude></span></div></div>'
        };
    });

大佬总结

以上是大佬教程为你收集整理的AngularJs directive-scope全部内容,希望文章能够帮你解决AngularJs directive-scope所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。