ngx-bootstrap icon indicating copy to clipboard operation
ngx-bootstrap copied to clipboard

Angular4 Dropdown Bug - "No provider for TemplateRef"

Open dmastag opened this issue 9 years ago • 17 comments

When using Dropdown with Angular4, its shows the error "No provider for TemplateRef"

dmastag avatar Mar 29 '17 14:03 dmastag

Same problem. Solved it?

nemanjan00 avatar Mar 29 '17 15:03 nemanjan00

For Angular 4 you must use 2.0.0-rc.0

Martin-Luft avatar Mar 29 '17 15:03 Martin-Luft

Fixed it by adding * in front of dropdownMenu and *dropdownToggle

nemanjan00 avatar Mar 29 '17 15:03 nemanjan00

I couldnt find 2.0.0-rc.0 by using yarn. and adding the * does not help. the error goes away but the dropdown is no longer acting as a dropdown

crh225 avatar Apr 07 '17 16:04 crh225

Version I am using: ng2-bootstrap@^1.3.3

nemanjan00 avatar Apr 08 '17 13:04 nemanjan00

Sorry... 1.6.3 is installed...

nemanjan00 avatar Apr 08 '17 13:04 nemanjan00

I´m also having the same problem. Just updated to ngx-bootstrap 1.6.3 running Angular 2.3.1. Does it only work on 4 now?

skulptur avatar Apr 10 '17 12:04 skulptur

Apparently asterik must be prefixed only to dropdownMenu and NOT to dropdown or dropdownToggle.

santoshkt avatar Apr 11 '17 04:04 santoshkt

@santoshkt this worked for me.

Can anyone explain why the asterisk was necessary to make this work again (after update to ngx-bootstrap and Angular 4)?

mashaalmemon avatar May 11 '17 17:05 mashaalmemon

i get the same issue.. use ngx-bootstrap v1.7.0 and angular 4 @valorkin when to use ng2-bootstrap and when to use ngx-bootstrap?

rkusuma avatar Jun 02 '17 10:06 rkusuma

@rkusuma Fixed it by adding * in front of dropdownMenu

valorkin avatar Jun 02 '17 12:06 valorkin

@mashaalmemon asteriks gives an option to use dropdownMenu element and content as template it was required change to add, attach to body option

valorkin avatar Jun 02 '17 12:06 valorkin

@valorkin still not works for me (ngx-bootstrap 1.7.0).. it works when i use ng2-bootstrap 2.0.0.rc0.

rkusuma avatar Jun 02 '17 13:06 rkusuma

So, from my experiences, this fixed the issue:

  • Add asterisk to dropdownMenu like this: *dropdownMenu
  • Do not add asterisk to the other markups like dropdown or dropdownToggle
  • The CSS class of dropdownMenu has to be dropdown-menu. (In my previous working version it was dropdown-menu-right.) So if the Angular works, but the CSS breaks, then it might be the problem.

newerik avatar Jun 20 '17 10:06 newerik

Check node_modules/ng2-bootstrap/index.js. The dropdown module, previously referenced as import { DropdownModule } from './dropdown/dropdown.module'; is likely using a new prefix: import { BsDropdownModule } from './dropdown/bs-dropdown.module';

That brings us to the necessity of a complete upgrade to ng4+ that comprises 2 parts:

  • Part 1 involves the ng-cli upgrade itself. See instructions here.

  • Part 2 is simply the upgrade from ng2-bootstrap to ngx-bootstrap(ng4+). Follow these steps:

  1. npm uninstall ng2-bootstrap --save
  2. npm install ngx-bootstrap --save
  3. In your app modules and components, change all ng2 prefixes to ngx.
  4. Follow @newerik's comments. While the bootstrap documentation shows the asterisk at its demo code, it is easy to miss this step in your upgrade because ng2 did not have the same asterisk. <ul *dropdownMenu class="dropdown-menu" role="menu">

Your drop-down should work fine thereafter.

pageii avatar Jul 17 '17 15:07 pageii

@newerik Thanks.. That solved my issue. But my whole projects font-size shrinked

rahul-krish avatar Jan 06 '18 07:01 rahul-krish

i got same error for [NgSwitch].. what can i do??

varshildoshi avatar Apr 23 '18 09:04 varshildoshi