PatrickJS / NG6-starter

:ng: An AngularJS Starter repo for AngularJS + ES6 + Webpack
https://angularclass.github.io/NG6-starter
Apache License 2.0
1.91k stars 1.35k forks source link

How to use ng-include #109

Open baj84 opened 8 years ago

baj84 commented 8 years ago

Hi,

I have a component that needs to have it's template split into multiple parts so that the logic can be shared. I need to have the main template including others (from the same directory) with all of them sharing the same scope and vm properties.

I've noticed that doing a simple

does not work.

I can load the template in via the controller and pass it to the view via a VM variable, but this does not share scope and seems to be messy.

Has anyone found a good way of doing this?

Cheers

fesor commented 8 years ago

In 80% of cases you can use function which provides you correct template for your component.

In other cases you could just add templates to templateCache manually and use ngInclude, but personally I consider usage of ngInclude as bad practice.

baj84 commented 8 years ago

Ah ok, thanks.

In my main template I have some bits of the template that may need to be included in several parts of the template. How would you do this without ng-include?

Cheers

fesor commented 8 years ago

@baj84 I will create separate reusable component with own template. Or if you have some "main" component which have the same layout from screen to screen and should contain differen components - multi transclude.