1

I got quite confused about the context of the template, see the code below

<script type="text/x-handlebars">
    <div>
        <h1>hello world</h1>
        {{view 'temp'}}
        {{render 'temp'}}
    </div>
</script>

var App = Ember.Application.create({
  LOG_TRANSITIONS: true
});

App.ApplicationController = Ember.Controller.extend({
    age: 13,
});

App.TempController = Ember.Controller.extend({
    age: 14,
});

App.TempView = Ember.View.extend({
    age: 123,
    template: Ember.Handlebars.compile('<div>{{age}}</div>')
});

For {{view 'temp'}}, it renders 13 since the view it use the application controller as its scope/context. For {{render 'temp'}}, from what my understanding, it will use TempView and TempController as its context. however, it renders nothing. Both 14 and 123 will not render. How it can render the age that assign to the view??

eded
  • 3,778
  • 8
  • 28
  • 42

1 Answers1

0

Use components, their scope is isolated.

Views are deprecated for all uses except the topmost level of a route. Ember 1.12 is expected to allow using components there too, then views will be deprecated completely.

Demo: http://emberjs.jsbin.com/zirevu/1/edit?html,js,output

Andrey Mikhaylov - lolmaus
  • 23,107
  • 6
  • 84
  • 133