Pergunta

I am much new to Ember.js, and trying to create an application where i need to surf through dates and privecy of records

What i want to do is, i need to pass one variable value through ember routes without showing it on url

appcication_routes.js.coffee

App.Router.map ->
  @resource 'user', { path: '/user/:user_id' }, ->
    @resource 'user_feed', { path: '/feed' }, ->
      @route 'posts', { path: '/:date' }

user_routes.js.coffee

App.UserFeedIndexRoute = App.Route.extend
  activate: ->
    controller = @controllerFor('user_feed.index')
    controller.set 'checkPrivate', false
  redirect: ->
    @transitionTo 'user_feed.posts', @modelFor('user'), 'today'

App.UserFeedPostsRoute = App.Route.extend
  activate: ->
    controller = @controllerFor('user_feed.posts')
  model: (params) ->
    ...

For transition from controller i used below string

@transitionToRoute 'user_feed.posts', @get('user'), newDateString

I need to pass value of checkPrivate to UserFeedPosts but without showing it to url, also i need to call the route againg on date change or checkPrivate value change.

I have googled it a lot but with zero success.

Foi útil?

Solução

You could use a shared controller (Ember Guide) which saves the state of the private variable.

App.ApplicationController = Em.Controller.extend({
  checkPrivate: null
});

Then, if you want to have accessible this value in a specific controller, you could import it with needs.

App. UserFeedPostsController = Em.ArrayController.extend({
  needs: ['application']
});

App.ApplicationController = Em.Controller.extend({
  needs: ['application']
});

If your case does not require to have accesible the data from the other controller, you can always access a specific controller from any route as:

this.controllerFor('application');
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top