I am trying to pass and argument to a directive via element attributes below is a snippet:
directive
app.directive('bgFluct', function(){
var _ = {};
_.scope = {
data: "@ngData"
}
_.link = function(scope, elem, attr) {
// if there is no image provided use pp.png the default
scope.background = scope.data !== undefined ? scope.data : '../../img/pp.png'
elem.css(
{
'background': 'url('+scope.background+')',
'background-size': 'cover',
'background-repeat': 'no-repeat',
'background-position': 'center center'
})
}
return _;
})
html
<div class="four columns" style="margin-right: 20px;">
<div class="row">
<div ng-data="{{ vm.background_image }}" class="project-item" bg-fluct>
</div>
</div>
</div>
In my directive console.log(scope) prints:
The main problem is scope has a data property (screenshot below) but I can't access it by scope.data
I have looked over my entire code again and again but still cant find a solution to this problem.
How can I go about accessing the ng-data property from the directive attribute ?
Cheers!

scope.background = scope.data !== undefined ? scope.data : '../../img/pp.png'<div ng-data="{{ vm.background_image }}" class="project-item" bg-fluct>for surevm.background_imagehas a valuebackground_imagefrom ajax? but still console.log is showing value ofdatain directive scopedatais not yet present, while initializing the directive. You could wait with initializing this directive until the value is there (e.g.ng-if="valueIsAvailable) or just$scope.$watchthe passed value and as soon it is another value, change the variable. Another way is to just access the passed variable in the view.