My intention was to use one template for multiple views with different controllers.
But now I understand that I canβt just write a universal binding in templates, because the values ββwill fit inside $scope.concreteControllerName .
Angular docs for ngInclude say that
This directive creates a new scope.
I could use the ng-init directive and pass the controller instance to the template area:
<ng-include src="..." ng-init="controller=concreteControllerName"/>
or even better
<ng-include src="..." ng-init="model=getModelForTemplate()"/>
and then write {{controller.boundvalue}} in the template.
This is a working solution, I think.
And here I would like to know if there are other more effective approaches, and if not, should templates always be used with some concept of the past model to abstract from the parent area?
source share