Я пытаюсь передать variation variable
от card.html
до tooltip.html
в ангулайсе.Однако по тем или иным причинам это не работает.Когда я console.log(scope.variation)
внутри interestRateTooltip.directive.js
, он показывает мне apr
.
Кроме того, в tooltip.html
, если у меня есть следующее
<div>
{{ variation }}
</div>
, оно отображает apr
внутри div.Поэтому я не понимаю, почему <i tooltip position="{{ variation === 'apr' ? 'left' : 'right'}}">
всегда будет ложным и становится right
.
Я провел 6 часов в поисках с утра.Может кто-нибудь, пожалуйста, помогите?Спасибо!
В card.html
<div>
<interest-rate-tooltip variation="apr"></interest-rate-tooltip>
</div>
В interestRateTooltip.directive.js
angular.module("borrower.offers").directive('interestRateTooltip', function () {
return {
restrict: "E",
templateUrl: ".../card.html",
link: function(scope, element, attrs) {
if (attrs.variation === 'apr') {
scope.variation = 'apr';
}
}
}
});
В tooltip.html
<div>
<i tooltip position="{{ variation === 'apr' ? 'left' : 'right'}}">
</div>
В tooltip.directive.js
angular.module("borrower.offers")
.directive("tooltip", function() {
return {
restrict: "A",
link: function(scope, element, attrs) {
var params = {};
switch (attrs.position) {
case 'left':
params = { position: 'bottom left' }
break;
case 'right':
params = { position: 'bottom right' }
break;
case 'center':
params = { position: 'bottom center' }
break;
}
}
}
});