1
我正在爲推廣指令,我得到一個奇怪的problem-
在下面的代碼有一個叫scope.promoDetailUrl, 當我和採取$ rootScope變量.configData ['PROMOTIONS']數據轉換成scope.promoDetailUrl變量,然後這在指令模板中工作正常。
但是,如果我在模板中使用configData ['PROMOTIONS'],那麼這是行不通的。
請看看我的代碼 -
(function(){
'use strict';
angular.module('promotions', [])
.directive('promotion', ['$interval', '$rootScope','HttpServiceCall', promotion])
function promotion($interval, $rootScope, HttpServiceCall){
return{
restrict:'EA',
templateUrl: 'partials/directive-templates/promotion-template.html',
replace:true,
scope:{
list:'='
},
compile: function(){
return{
post: function postLink(scope, iElement, iAttrs) {
console.log("listDirective",scope.list,$rootScope)
var startData = moment(scope.list.StartDate);
var endDate = moment(scope.list.EndDate);
scope.diff = {};
scope.list.image = environments[env].RESOURCE_URL_AMAZON + environments[env].AMAZON_PROMOTION_FOLDER_PATH + scope.list.image;
scope.promoDetailUrl = $rootScope.configData['PROMOTIONS'];
}
}
}
}
}
}())
<div class="col-xs-12 col-sm-4 promotion-pro" ng-show="isHMSisZero === 'false'">
<div class="pro-other-option-box">
<figure ng-attr-title="{{list.altTag}}"><img ng-src="{{list.image}}"></figure>
<div>
<h3>{{list.title}}</h3>
<p>{{list.shortDescription}}</p>
<div class="timer-section clearfix">
<!-- <p><a href="{{list.moreInfo}}">{{'link_more_info' | translate}}</a></p> -->
<!-- not working -->
<p><a href="#/{{configData['PROMOTIONS']}}/{{list.promoID}}">{{'link_more_info' | translate}}</a></p>
<div class="pro-option-timer">
<div class="timer-current">
<strong>{{'promo_list_offer_text' | translate}}</strong>
<span class="time-detail"><span ng-show="diff.days>0">{{diff.days}} {{'promo_list_days' | translate}} </span> <span ng-show="isHMSisZero === 'false'">{{diff.hours}} : {{diff.minutes}} : {{diff.seconds}}</span></span>
</div>
</div>
</div>
</div>
</div>