I'm trying to create a directive that will load the page and make it available in a service and as scope and it's going to have content inside the directives element.
This should be pretty self-explaining (simplified) what I try to do:
<cms-page page-id="829">
<h1>Testing</h1>
<ul ui-sortable ng-model="pageData.sections.main">
<li ng-repeat="element in pageData.CmsPage.sections.main track by $index">
<div ng-include="'/templates/cms/elements/' + element.element_type + '.html'"></div>
</li>
</ul>
<pre>{{pageData | json}}</pre>
</cms-page>
The issue with that is now that it doesn't show the {{pageData}}. How can I create a directive that will show the existing markup and parse the existing markup and child directives?
Here is my directive:
angular.module(cms).directive('cmsPage', ['CmsPage', 'CmsPagesService', function(CmsPage, CmsPagesService) {
return {
restrict: 'E',
transclude: true,
template: '<div ng-transclude></div>',
scope: {
pageId: '@pageId'
},
controller: function($scope) {
$scope.pageData = {};
CmsPagesService.get($scope.pageId).then(function(result) {
if (result.status == 'success') {
$scope.pageData = result.data;
} else {
throw 'Page failed to load.';
}
});
$scope.$watch('pageData', function() {
CmsPage.setPage($scope.pageData);
});
}
};
}]);