html - How to pass string argument to template using Angular -


for following template:

<h2 class="viewtitle">{{viewtitle | translate}}</h2> 

i'm passing translatable string, variable in scope. if include template this:

<div ng-init="viewtitle = 'translatable.title'" ng-include="'views/templates/view-title.html'"/> 

things work. however, cannot pass variable scope. how accomplish both?

your main issue this:

how set scope property ng-init?. reading scope attribute ng-init before angular had time write it. cannot access $scope attributes in ng-init. instead set $scope attributes in controller (js code).

these additional issues encounter:

this work (see below), encountering typical angular scoping issues, there 2 possible solutions:

always follow dot-rule (https://egghead.io/lessons/angularjs-the-dot), avoid many scoping issues in our career

or use "controller as" syntax (http://toddmotto.com/digging-into-angulars-controller-as-syntax/).

template:

<h2 class="viewtitle">{{myscopeattributeinparentscope | translate}}</h2> data: {{myscopeattributeinparentscope}}   

using string:

<div ng-init="myscopeattributeinparentscope=translatable.title'}" ng-include="'views/templates/view-title.html'"/> 

using scope attribute:

<div ng-include="'views/templates/view-title.html'"/>   parent scope: {{myscopeattributeinparentscope}}  

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -