Our application is now incorporating reusable code by creating a simple directive to display content efficiently.
Directive Code:
angular.module("newsStore.moduleDirectives", [])
.directive('renderAboutContent', ['aboutService', renderAboutContent]);
function renderAboutContent(aboutService) {
return {
restrict: 'AE',
scope: {},
templateUrl: 'templates/about.html',
link: function (scope, element) {
aboutService.getAboutContent()
.then(function (results) {
scope.aboutList = results.aboutContent.listItems;
}, function (error) {
console.log('controller error', error);
});
}
}
}
HTML code:
<div class="col-md-12 aboutUs-ph padT10 content-ph_abt" ng-repeat="content in aboutList">
<div class="col-md-2 form-group" ng-if="content.image">
<img src="{{content.image}}" class="img-responsive" />
</div>
<div class="col-md-9">
<span class="guidedTourText"><b>{{content.title}}</b></span>
<br>
<span>{{content.description}}</span>
</div>
</div>
Question:
The HTML code above shows col-md-2 and col-md-9 inside col-md-12. If there are three div elements with content occupying 4, 4, 4 respectively, but the last one has no content, we want the remaining two divs to take up 6 each instead of 4. This behavior needs to be implemented through the directive.
Please let me know if I need to clarify anything further.