angularjs - What are the best practices of using ngInclude with ControllerAs syntax? -


I intend to use a template in many views with different controllers.

But now I realize that I can not just write universal bindings in templates because the value is $ scope.concreteControllerName . Will be put in.

Connectional Documents to Say

This instruction creates new scope.

I can use the ng-init instructions and pass controller example from the scope of the template:

    

or better

   Type in the  

and then {{controller.boundvalue}} template.

This is a working solution, I think.

And here I would like to know if there are other better ways and if not, then what templates can always be used to remove originally with some ideas of the passed model?

Use John Papa and you will see separate code in ng-included instructions. But the same sources use the HTML template. The normal vm variable name is used in the template.

index.html

  & lt; Div ng-ng-controller = "controllerOne as vm" src = "'same.html" "& gt; & lt; / div & gt; & lt; div ng- contains ng-controller =" controller two vm "src = "'Same.html" "& gt; & Lt; / Div & gt; & Lt; Div ng- included ng-controller = "controller" as VM "src =" 'same.html "" & gt; & Lt; / Div & gt;  

controllerOne.js

  function controller one () {var vm = this; Vm.name = 'Controller one!';  

sharedTemplate.html

  & lt; Div & gt; {{Vm.name}} & lt; / Div & gt; Here is a full version: 


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -