I am working on my Ionic 2 component ionic2-autocomplete, which was originally developed for RC.4 and earlier versions, and now I am trying to migrate it to Angular 2 final.
As part of the original design, I let the developers overwrite the default template by using a custom decorator AutoCompleteItem
which accepts template
or templateUrl
.
The source code of this decorator could be found here.
As you can see, I used the decorator in order to preserve some of the attributes required for my component, alongside letting the users design the component for their own needs.
Now, following the exact same steps I wrote in the docs, I tried to implement a custom template by using:
import {AutoCompleteItem, AutoCompleteItemComponent} from 'ionic2-auto-complete';
@AutoCompleteItem({
template : `<img src="build/images/flags/{{data.name}}.png" class="flag" /> <span [innerHTML]="data.name | boldprefix:keyword"></span>`,
})
export class CompTestItem extends AutoCompleteItemComponent{
}
Which worked perfectly on the earlier versions (I also added the CompTestItem
to the declerations
array).
But for some reason, I now encounter the following exception:
polyfills.js:3 Unhandled Promise rejection: Template parse errors: More than one component: AutoCompleteItemComponent,CompTestItem ("
[ERROR ->] ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors: More than one component: AutoCompleteItemComponent,CompTestItem ("
[ERROR ->]http://localhost:8101/build/main.js:19480:19) at RuntimeCompiler._compileTemplate (http://localhost:8101/build/main.js:27855:51) at http://localhost:8101/build/main.js:27777:83 at Set.forEach (native) at compile (http://localhost:8101/build/main.js:27777:47) at t.invoke (http://localhost:8101/build/polyfills.js:3:13400) at e.run (http://localhost:8101/build/polyfills.js:3:10787) at http://localhost:8101/build/polyfills.js:3:8889 at t.invokeTask (http://localhost:8101/build/polyfills.js:3:14029) at e.runTask (http://localhost:8101/build/polyfills.js:3:11389)o @ polyfills.js:3r @ polyfills.js:3i @ polyfills.js:3 polyfills.js:3 Error: Uncaught (in promise): Error: Template parse errors:(…)o @ polyfills.js:3r @ polyfills.js:3i @ polyfills.js:3
I really don't have a clue why. Could anyone have a clue why this custom decorator wont work on this version of Angular? And why does it say that I have more than one component?
Thanks!
exports: [ AutoCompleteItemComponent ]
. Not sure why that causes a problem but it makes sense that it wasn't a problem before modules were introduced to Angular. Solution? Not sure, since you need to export it to use it multiple modules. If you always had to extend it, then there is no need to ever declare and/or export it, but it looks like it's a component that could also be used standalone – Paul Samsotha[Error ->]
is pointing to - the element - Angular can't decide which component to use – Paul Samsotha