gpt4 book ai didi

javascript - 指令在 ionicModal 中首先遵守,甚至在 Controller 加载之前

转载 作者:行者123 更新时间:2023-11-29 15:34:47 24 4
gpt4 key购买 nike

我有一个 $ionicModal,里面有一个指令,我们称它为 <scrap-link-cards> ,这采用范围对象的双向数据绑定(bind)值。这是在 $ionicModal 模板中:-->

<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 的模板:

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

请注意,这是在 $ionicModal 中:

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

现在这是我的问题,因为它在 $ionicModal 中,在 angular 可以访问 (updates.updates_links) 之前,HTML 被编译。我在 $scope.links 处得到一个 undefined object .我该如何解决这个问题?我已经尝试使用指令的链接函数,(移动了链接中的所有逻辑)仍然..我认为 $ionicModal 模板是在 Controller 加载之前编译的?是吗?

最佳答案

我设法创建的唯一解决方法是停止编译函数,直到到达 Modal 的指令。使用 ng-if并用 div 包装指令.

在 Modal 的模板中:

<div ng-if="updates">
<scrap-link-cards datasource=(updates.update_links)> </scrap-link-cards>
</div>

这样编译器就会离开指令,只有在用户打开模式时才会执行。

关于javascript - 指令在 ionicModal 中首先遵守,甚至在 Controller 加载之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30526884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com