javascript - angular的指令问题
巴扎黑
巴扎黑 2017-04-10 14:49:51
[JavaScript讨论组]

我想写一个类似angularUI的tabset directive,看了一下源码,不是很明白。

HTML结构如下:

html
    
    

JS代码:

javascriptangular.module('angularTabset',[])
.directive('tabset',function(){
    return {
        restrict:'EA',
        replace: true,
        transclude: true,
        templateUrl: 'tabset.html',
        scope:{
            a:'=?',
            b:'=?',
            c:'=?'
        },
        controller:function($scope){
            this.a = $scope.a;
            this.b = $scope.b;
            this.c = $scope.c;
        },
        link: function (scope, iElement, iAttrs) {

        }
    }
})
.directive('tab', function () {
    return {
        restrict: 'EA',
        replace: true,
        require:'^tabset',
        transclude: true,
        templateUrl: 'tab.html',
        controller: function($scope){
            //How to get a,b,c here?
        },
        link: function (scope, iElement, iAttrs,ctrl) {

        }
    };
})

问题:

tab.html模板里用到了tabsetController里的a、b、c属性的值,我想在tabController里访问这三个值并实现双向绑定,该如何写?我试过在link函数里写,但貌似只执行一次,没有实现双向绑定。

巴扎黑
巴扎黑

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号