0

I get the data in HTML format. (because we use content mgmt). My task is to write a directive to parse this data into javascript object and then use template to display properly.

My problem is, when inside link method, the template is getting replaced, before I can operate on this HTML data.

My HTML content

<body>
<div ci-course-calendar>
    <div class="ci-course-calendar-item">
        <div class="ci-course-calendar-item-title">Title</div>
        <div class="ci-course-calendar-item-summary">Summary</div>
        <div class="ci-course-calendar-item-date">Jan 21, 2016</div>
    </div>
   <div class="ci-course-calendar-item">
        <div class="ci-course-calendar-item-title">Title</div>
        <div class="ci-course-calendar-item-summary">Summary</div>
        <div class="ci-course-calendar-item-date">Jan 21, 2016</div>
    </div>
<div>
</body>

My template of the directive - ci-course-calendar

<div class="accordion">
   <div ng-repeat="course in courses">
       <!--do  something-->
   </div>
</div>
Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Dew
  • 139
  • 2
  • 15
  • 1
    I think that you need to use `compile` function instead of `link`. See this question: http://stackoverflow.com/questions/24615103/angular-directives-when-and-how-to-use-compile-controller-pre-link-and-post – Mosh Feu Feb 09 '16 at 08:15
  • @MoshFeu , looks like the compile function executes only once for a directive, but I need to parse this data each time the directive is used.. The link you shared was useful...but still confused, what needs to be used. – Dew Feb 09 '16 at 10:25
  • Are those div's inside of `ci-course-calendar` hard coded by you? Can't you just grab these values inside of your controller with `ng-model`? After that you can pass these values to you directive through the isolated scope? – Peter Feb 09 '16 at 10:37
  • @peter these values comes from CQ5(content mgmt), so I need to parse this inside directive and then use it appropriately in template. – Dew Feb 09 '16 at 12:55

0 Answers0