문제

as I mentioned in several questions here I am migrating an already existing and running Ember project to use Ember App Kit and I ran into several problems... here's another "problem" which wasn't a problem before :)

I've got a NotificationCollectionController which is placed under app/controllers/notification/collection.js.

file 'app/controllers/notification/collection.js':

export default Ember.ArrayController.extend({
  addNotification: function (options) {
    // some code
  },
  notifyOnDOMRemove: function (notification) {
    this.removeObject(notification);
  }
});

As this is the controller for notifications which are rendered through a named outlet I didn't declare a route for it.

Within my ApplicationRoute I want to access this controller within a function

file: 'app/routes/application.js'

import BaseRoute from 'appkit/routes/base';

export default BaseRoute.extend({
  addGlobalNotificationCollection: function () {
    var controller = this.controllerFor('notificationCollection');
    // some more code...
  }
});

But as soon as the application starts and this piece of code gets called I traced down the following error:

"Assertion Failed: The controller named 'notificationCollection' could not be found. Make sure that this route exists and has already been entered at least once. If you are accessing a controller not associated with a route, make sure the controller class is explicitly defined."

What does it mean and why is it thrown? What do I have to do to make it run again?

도움이 되었습니까?

해결책

I didn't recognize that the hint is already given at the Naming Conventions section of the Ember App Kit Webpage:

It says, that the naming convention for a Controller is, for example: stop-watch.js

And if it’s a route controller, we can declare nested/child controllers like such: app/controllers/test/index.js

So I placed my NotifcationCollectionController in controllers/notification-collection.js and call it like Route#controllerFor('notification-collection') and everything works as expected :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top