指令在ionicModal符合第一,甚至前装控制器 [英] Directive In ionicModal complies first, before even controller loaded

查看:177
本文介绍了指令在ionicModal符合第一,甚至前装控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个$ ionicModal和里面我有一个指令,让我们把它叫做<报废链路卡和GT; ,这需要在一个双向数据绑定一个范围对象的值。这是一个$ ionicModal模板中: - >

I have a $ionicModal and inside that I have a directive, lets call it <scrap-link-cards> , this takes in the a two way data bind value of a scope object. This is inside a $ionicModal template:-->

<scrap-link-cards datasource=(updates.update_links)> </scrap-link-cards> 

这是我的全部指令:

.directive('scrapLinkCards', function ($log) {
        var controller = function ($scope) {
            $scope.links = angular.copy($scope.datasource); //undefined
            $scope.LastIndex = $scope.links.length - 1;
        };
       var templateUrl ='/path/to/template' ;

        return{
            restrict :'E',
            controller: controller,
            scope: {
              datasource :'='
            },
            templateUrl : templateUrl
        }
    })

这是我的templateUrl的模板:

This is my templateUrl's Template:

<div class="scrapLinks">
    <h3>{{links[LastIndex].title}}</h3>
    <p>{{links[LastIndex].description}}</p>
</div>

请注意,这是一个$ ionicModal内:

Please NOTE that, this is inside a $ionicModal:

$ionicModal.fromTemplateUrl('path/to/template/html', {
        scope: $scope,
        animation: 'slide-in-up'
    }).then(function ($ionicModal) {
        $scope.ReadMore = $ionicModal;
});

现在这里是我的问题,因为它的一个$ ionicModal 里面,HTML得到遵守,前角可以访问(updates.updates_links)。我会在 $ scope.links 一个未定义的对象。我怎样才能解决这个?我曾尝试使用链接功能指令,(在移动连接所有的逻辑)仍..我认为控制器加载之前$ ionicModal模板编译?是吗?

Now here is my problem, since its inside a $ionicModal, the HTML gets complied, before angular can have access to (updates.updates_links). I get a undefined object at $scope.links. How can I workaround this? I have tried using link function of directive, (moved all the logic in link) still.. I think $ionicModal templates are compiled before controller loaded ? Is it?

推荐答案

我周围设法建立唯一的工作是停止编译功能,达到历史上模态的指令。使用 NG-如果和包装的指令,一个 DIV

The only work around I managed to create is to stop the compile function to ever reaching the Modal's directive. Using a ng-if and wrapping the directive with a div.

在模态的模板:

&LT; D​​IV NG-IF =更新&GT;
&LT;报废链路卡数据源=(updates.update_links)GT; &LT; /报废链路卡和GT;
&LT; / DIV&GT;

当用户打开模态通过这种方式,编译离开指令和唯一的要求。

This way the complier leaves the directive and only complies when the user opens the modal.

这篇关于指令在ionicModal符合第一,甚至前装控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆