Ember容器注入对象

Ember注入是用来将一个对象注入到一个容器里面去,让容器可以访问对象,容器是指routecontrollerhelper

使用用例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// app/services/session.js
export default Ember.Service.extend({
  isAuthenticated: false
});

// app/initializes/inject-session.js
export function initialize(application) {
  application.inject('route', 'service:session');
}

export default {
  name: 'session',
  initialize: initialize
}


// app/routes/products.js
export default Ember.Route.extend({

  model(){
    this.session
  },
  setupController(controller, model){
    this.session
    ...
  }
});

Comments

Copyright © 2017 kaka