I am currently in the process of constructing my initial Angular application, but I am encountering some difficulties while attempting to achieve a specific functionality. The issue revolves around a video container which is supposed to remain hidden until $scope.video.show = true; I aim to alter this value upon clicking on a particular link by implementing it within a directive. Any assistance or guidance in this matter would be greatly appreciated.
html:
<div ng-controller="AppCtrl">
<div ng-cloak
ng-class="{'show':video.show, 'hide':!video.show}">
// youtube iframe content, for example
</div>
<div>
<ul>
<li>
<h3>Video Headline 1</h3>
<button type="button"
video-show
data-video-id="jR4lLJu_-wE">PLAY NOW ⟩</button>
</li>
<li>
<h3>Video Headline 2</h3>
<button type="button"
video-show
data-video-id="sd0f9as8df7">PLAY NOW ⟩</button>
</li>
</ul>
</div>
</div>
Javascript:
var angularApp = angular.module("savings-video", [])
.controller('SavingsVideoController', function($scope) {
$scope.video = {
show : false,
videoId : ""
};
};
angularApp.directive("videoShow", function(){
return{
restrict: 'A',
link: function(scope , element){
element.bind("click", function(e){
var $selectedElement = angular.element(element);
$selectedElement.closest('li').siblings().addClass('hide'); // hide the other one
$selectedElement.closest('li').removeClass('hide'); // keep me open
scope.video.show = true; // struggling to make it work
// what is the optimal approach to accomplish this?
});
}
}
});