I am really new to directives in Angular previously what I am doing I would achieve with some form of ng-include and passing variables around in dirty ways.
I am very confused on the scope of directives and what they're capable of, also I am aware that once a directive is used inside of ng-repeat the variables behave differently.
To understand what I am looking for you need the whole picture. I have these emails stored in a database. Each email has typical properties, I wrote a directive to display each one using ng-repeat.
app.directive('emailListing', function ($filter) {
return {
restrict: 'AE',
replace: 'true',
templateUrl: '../Pages/Views/Templates/emailListing.html',
scope: {
Date: "@",
Email: "@",
Content: "@",
Read: "@",
Subject: "@"
},
link: function (scope, elem, attrs) {
scope.Date = attrs.date;
scope.Email = attrs.email;
scope.Content = attrs.content;
scope.Subject = attrs.subject;
if (attrs.isnew == 'true') {
scope.Read = "logo-unread";
} else {
scope.Read = "logo-read";
}
scope.Date = $filter('date')(scope.Date, 'MM-dd-yyyy');
}
};
});
The directive in HTML
<email-Listing ng-repeat="items in AllEmails | filter:{message: contentEmail} | limitTo:10" email="something@live.com"></email-Listing>
HTML Template
<div class="news-row row">
<label>{{email}}</label>
</div>
I now am facing a problem where I want to use Angular's UI bootstrap.modal directive. I want to be able to click something within my template and it will bring up the modal with the data from this scope.
First of all, I need to make the values I pass into it, for example email="something@live.com" be data-bound to some object residing in my controller. I don't understand how to achieve this because, removing the link function and changing the scope to have "=email" makes nothing work.
Can someone help me write a directive that accepts values like date, email, content, isRead, and subject. These values are provided by ng-repeat, and lastly the values in this directive must bind back to the controller so that changing them per-say in a modal will update them in the directive too.