Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the generalizable way to get values out of a directive?
    primarykey
    data
    text
    <p>I'm writing a little threaded discussion board in angular. I want to use hallo.js for my inline editor (or something similar, the problem doesn't actually depend on hallo).</p> <p>Here's the relevant snippet from the template</p> <pre><code>&lt;div ng-show="post.editing" ng-bind-html="post.body" edit-hallo class="col-xs-8"&gt;&lt;/div&gt; &lt;div ng-show="!post.editing" ng-bind-html="post.body" class="col-xs-8"&gt;&lt;/div&gt; </code></pre> <p>Here's my directive:</p> <pre><code>Appl.directive('editHallo', function () { return { restrict: 'AC', scope: true, link: function(scope, element, attr) { element .hallo({ plugins: { 'halloformat': {"bold": true, "italic": true, "strikethrough": true, "underline": true}, 'halloheadings': [1,2,3], 'hallojustify' : {}, } }); element.bind('hallomodified', function(event, data) { scope.post.body = data.content; }); } }; }); </code></pre> <p>This all works just fine, but the hack is right there at the end - when there's a hallomodified event, I manually say, <code>scope.post.body = data.content</code> which not only feels like a hack, it means this only works when there's a post.body item that I'm editing, and therefore doesn't work well if I want to repurpose this for the profile editor or whatever.</p> <p>So my question is: how should I refactor this so that the relevant two-way binding works? I tried a few things that seemed obvious, such as putting a <code>app-model="post.body"</code> in the div, and then doing an isolate scope with =, but that wasn't getting me anywhere. Ideally, I'd pass in the appropriate model using an ng-model directive, but that seems to have changed sometime between when all the directive examples I found online were created and angular 1.2.0.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload