{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/11030","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/11030/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/11030/comments","events_url":"https://api.github.com/repos/angular/angular/issues/11030/events","html_url":"https://github.com/angular/angular/issues/11030","id":172893364,"number":11030,"title":"ComponentFactoryResolver - No component factory found for \"MyComponent\"","user":{"login":"ssmartin","id":17272626,"avatar_url":"https://avatars.githubusercontent.com/u/17272626?v=3","gravatar_id":"","url":"https://api.github.com/users/ssmartin","html_url":"https://github.com/ssmartin","followers_url":"https://api.github.com/users/ssmartin/followers","following_url":"https://api.github.com/users/ssmartin/following{/other_user}","gists_url":"https://api.github.com/users/ssmartin/gists{/gist_id}","starred_url":"https://api.github.com/users/ssmartin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ssmartin/subscriptions","organizations_url":"https://api.github.com/users/ssmartin/orgs","repos_url":"https://api.github.com/users/ssmartin/repos","events_url":"https://api.github.com/users/ssmartin/events{/privacy}","received_events_url":"https://api.github.com/users/ssmartin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-24T08:26:16Z","updated_at":"2016-08-25T06:39:04Z","closed_at":null,"body":"**I'm submitting a ...**  (check one with \"x\")\r\n```\r\n[ ] bug report => search github for a similar issue or PR before submitting\r\n[x ] feature request\r\n[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n```\r\n\r\n**Current behavior**\r\nWe used the DynamicComponentLoader in order to create components dynamically based on their Type. We also needed to provide specific list of Provider for our component. All this worked like a charm. \r\nWe have a (list) of pagePanel components that have this template:\r\n\r\n```\r\n template: `\r\n        <div role=\"pagepanel\" class=\"page-pane\" [ngClass]=\"{active: pageHandler.active}\">\r\n            <div #container></div>\r\n        </div>\r\n    `\r\n....\r\n\r\n  @ViewChild('container', { read: ViewContainerRef })\r\n    container: ViewContainerRef;\r\n```\r\nAnd we were doing something like this:\r\n```\r\nthis._dynaCompLoader.loadNextToLocation(\r\n            this.pageHandler.descriptor.componentType,\r\n            this.container,\r\n            resolvedProviders).then((componentRef: ComponentRef<any>) => {\r\n                this.pageHandler.initialize(componentRef);\r\n            });\r\n\r\n```\r\n\r\nThen the dcl was deprecrated and I moved to the ComponentResolver. Our code became:\r\n\r\n```\r\nthis._componentResolver.resolveComponent(this.pageHandler.descriptor.componentType)\r\n            .then((factory: ComponentFactory<any>) => {\r\n                let componentRef: ComponentRef<any> = this.container.createComponent(factory, 0,       this._childInjector);\r\n                this.pageHandler.initialize(componentRef);\r\n            });\r\n```\r\nSo far so good. Now with the new ComponentFactoryResolver I tried to migrate by doing something like this:\r\n\r\n```\r\n    let factory: ComponentFactory<any> = this._componentFactoryResolver.resolveComponentFactory(this.pageHandler.descriptor.componentType);\r\n        let componentRef: ComponentRef<any> = this.container.createComponent(factory, 0, this._childInjector);\r\n        this.pageHandler.initialize(componentRef);\r\n\r\n```\r\nBut now I get an exception -  _No component factory found for \"MyComponent\"_.  \r\nSo I read a bit more about it and surprise: seems that in order for this to work I HAVE to declare the component I want to dynamically create in the _entryComponents_ section of my module. \r\nLike this it works indeed, but **I consider this a regression because it kind of beats the purpose of being able to create components dynamically, without having to declare them in advance** -> the whole idea in our app was to be able to create these components just based on some metadata (including their TYPE). Because most of them are created like this and it would be really bad /hardfor me to add all of them to the _entryComponents_ section. \r\nI understand that I might be able to use the Compiler instead but then no chance to do AOT in production.\r\n\r\n**Expected/desired behavior**\r\n\r\nI would really like to be able to use the ComponentFactoryResolver similar to the ComponentResolver **without** having to declare all my components in the _entryComponents_ section. The goal is to still be able to use AoT in the future.\r\n\r\n**Reproduction of the problem**\r\n\r\nCheck this plunker (removing the _entryComponents_ will break it) - http://plnkr.co/edit/P0spNzu8JbQad2aKACsX?p=preview. \r\n\r\n\r\n**What is the expected behavior?**\r\n\r\nTo have a way to dynamically create components similar to how the DynamicComponentLoader was working (e.g. without having to declare the list of the components). Ideally to still be able to use AoT but I think this might be tricky/problematic.\r\n\r\n**What is the motivation / use case for changing the behavior?**\r\n\r\n\r\n\r\n**Please tell us about your environment:**\r\n\r\n* **Angular version:** 2.0.0-rc.5\r\n \r\n* **Browser:** [all ] \r\n \r\n* **Language:** [TypeScript  ] \r\n"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/242294249","html_url":"https://github.com/angular/angular/issues/11030#issuecomment-242294249","issue_url":"https://api.github.com/repos/angular/angular/issues/11030","id":242294249,"user":{"login":"mlc-mlapis","id":5693835,"avatar_url":"https://avatars.githubusercontent.com/u/5693835?v=3","gravatar_id":"","url":"https://api.github.com/users/mlc-mlapis","html_url":"https://github.com/mlc-mlapis","followers_url":"https://api.github.com/users/mlc-mlapis/followers","following_url":"https://api.github.com/users/mlc-mlapis/following{/other_user}","gists_url":"https://api.github.com/users/mlc-mlapis/gists{/gist_id}","starred_url":"https://api.github.com/users/mlc-mlapis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlc-mlapis/subscriptions","organizations_url":"https://api.github.com/users/mlc-mlapis/orgs","repos_url":"https://api.github.com/users/mlc-mlapis/repos","events_url":"https://api.github.com/users/mlc-mlapis/events{/privacy}","received_events_url":"https://api.github.com/users/mlc-mlapis/received_events","type":"User","site_admin":false},"created_at":"2016-08-25T06:39:04Z","updated_at":"2016-08-25T06:39:04Z","body":"If you count that there will not be a compiler on a browser side then who will compile a cmp? That is the reason why entryComponents exists and AoT uses it to find out what should compile and what include to a module. When the module is loaded (directly or as lazy loaded) those compiled cmps are loaded also and you can manipulate with them dynamically. In other case you need A2 compiler in a browser and compile cmps on demand. But A2 compiler is the biggest part of A2 - nearly 60% of code."}}
{"actor":{"display_login":"mlc-mlapis"}}