Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directive's content as bound data #77

Closed
thomaslhostis opened this issue Sep 23, 2015 · 8 comments
Closed

Directive's content as bound data #77

thomaslhostis opened this issue Sep 23, 2015 · 8 comments

Comments

@thomaslhostis
Copy link
Contributor

Is there a way to automatically bind the directive's html content to the data?

@outsideris
Copy link
Member

@thomaslhostis
Copy link
Contributor Author

I'm sorry it was not what I meant. Let's say that, when the page loads, my summernote element already has some content. Something like:

<summernote>
    <p>Hello World</p>
</summernote>

When the directive is loaded, <p>Hello World</p> just disappears. How do you avoid that?

@outsideris
Copy link
Member

@thomaslhostis
I meant it.
Use ngModel like <summernote ng-model="text"></summernote>, and assign the text in your controller like $scope.text = "<p>Hello World</p>";.
See example for more detail.

@thomaslhostis
Copy link
Contributor Author

@outsideris
Exactly, I want to avoid assigning the text in the controller. What I could do is:

<summernote ng-model="text" ng-init="text='<p>Hello World</p>'"></summernote>

But I'd rather be able to do this:

<summernote><p>Hello World</p></summernote>

Is it possible, with your directive as it is, to easily do that?

@thomaslhostis
Copy link
Contributor Author

@outsideris
I added the ng-transclude attribute to your directive's template and it works for me:

...
template: '<div class="summernote" ng-transclude></div>'
...

If you define a ng-model and set its value, it takes over the directive's HTML content. So I'm wondering, is there a reason why you didn't use ng-transclude?

This is great work, by the way.

@outsideris outsideris reopened this Sep 25, 2015
@outsideris
Copy link
Member

@thomaslhostis
There is no reason. Honestly, I don't know about ng-trasclude much.
Please explain about trasclude to me with more detail and what benefit it provide.
And PR also is always welcome.

@thomaslhostis
Copy link
Contributor Author

Sure, I'll create a PR :-)

"Transclude is a setting to tell angular to capture everything that is put inside the directive in the markup and use it somewhere in the directive's template." http://stackoverflow.com/questions/24725399/what-is-ng-transclude

@outsideris
Copy link
Member

Great!! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants