I am trying to create a directive so i dont have to repeat a set of HTML 10+ times.
Here's the original HTML:
<div class="abc">
<div class="xyz">
<div class="something">
<div class="hello">
<ul class="list">
<li ng-repeat="myData in Data.Info | filter:{ SectionID: 4 } | filter:{ Message: '!!' }">
<span ng-class="{'1': 'red', '2': 'blue'}[myData.MessageImage]"></span>
{[{ myData.Message }]}
</li>
</ul>
</div>
</div>
<div class="l">
<div class="nop">
<ul class="change">
<li ng-repeat="myData in Data.Info | filter:{ SectionID: 4 } | filter:{ Message: '!!' }">
<span ng-class="{'1': 'down', '2': 'up'}[myData.MessageImage]"></span>
</li>
</ul>
</div>
</div>
</div>
</div>
My directive:
app.directive('myNewDirective', function () {
return {
restrict: 'E',
replace: 'true',
scope: {
SectionID: '='
},
template:'<div>' +
'<span ng-class="{\'1\': \'red\', \'2\': \'blue\'}[myData.MessageImage]"></span>' +
'{[{ myData.Message }]}' +
'</div>',
link: function(scope, element, attrs) {
console.log("scope = " + scope);
console.log("scope.SectionID = " + scope.SectionID);
}
};
});
Here's how i tried calling my new directive:
<div my-new-directive SectionID="4">
However in my console.log, scope.SectionID = undefined
And hence why i have not stated the ng-repeat in my directive template.