Zvar Yuga
Zvar Yuga

Reputation: 21

Angular 4 Can't bind to 'dragula' since it isn't a known property of 'div'

I'm struggling with binding ng2-dragula to AspNetCore SPA template. Tried everything, but still getting:

Exception: Call to Node module failed with error: Error: Template parse errors:
Can't bind to 'dragula' since it isn't a known property of 'div'. ("
<div>
<div class='wrapper'>
<div class='container' [ERROR ->][dragula]='"first-bag"'>
<div>Drag/drop item 1</div>
</div>
"): ng:///AppModule/DragulaComponent.html@7:31
at syntaxError (C:\Users\...\ClientApp\dist\vendor.js:36125:34)
at ...

Has anyone used ng2-dragula in AspDotnetCoreSpa?

dragula.component.html

<div>
 <div class='wrapper'>
  <div class='container' [dragula]='"first-bag"'>
   <div>Drag/drop item 1</div>
  </div>
 </div>
</div>

dragula.component.ts

import { Component } from '@angular/core';
import { DragulaModule, DragulaService } from 'ng2-dragula'

@Component({
   selector: 'dragula',
   templateUrl: './dragula.component.html',
   styleUrls: ['../../../../node_modules/dragula/dist/dragula.min.css']
 })
 export class DragulaComponent {
}

app.module.client.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { DragulaModule } from 'ng2-dragula';
import { HttpModule } from '@angular/http';
import { sharedConfig } from './app.module.shared';

@NgModule({
    bootstrap: sharedConfig.bootstrap,
    declarations: sharedConfig.declarations,
    imports: [
        BrowserModule,
        FormsModule,
        DragulaModule,
        HttpModule,
        ...sharedConfig.imports
    ],
    providers: [
        { provide: 'ORIGIN_URL', useValue: location.origin }
    ]
})
export class AppModule {
}

app.module.shared.ts

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { AppComponent } from './components/app/app.component'
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';
import { DragulaComponent } from './components/dragula/dragula.component';

export const sharedConfig: NgModule = {
    bootstrap: [ AppComponent ],
    declarations: [
        AppComponent,
        NavMenuComponent,
        CounterComponent,
        FetchDataComponent,
        DragulaComponent,
        HomeComponent
    ],
    imports: [
        RouterModule.forRoot([
            { path: '', redirectTo: 'home', pathMatch: 'full' },
            { path: 'home', component: HomeComponent },
            { path: 'counter', component: CounterComponent },
            { path: 'fetch-data', component: FetchDataComponent },
            { path: 'dragula', component: DragulaComponent },
            { path: '**', redirectTo: 'home' }
        ])
    ]
};

Upvotes: 2

Views: 1815

Answers (2)

Azmath Ikram
Azmath Ikram

Reputation: 25

I hope you are using a module base structure(as below):

Click : Project Structure

In this application there are modules like dashboard, dragula..etc.

In this case if you want to add dragula drag and drop (ng2-dragula), what you have to do is, add DragulaModule in the app.module.ts using import { DragulaModule } from '../../node_modules/ng2-dragula/ng2-dragula';

once you add like this and if you try to use [dragula]='"bag-something"' in the dragula.component.html, which is the html file, still it will give the error Can't bind to 'dragula' since it isn't a known property of 'div'.

So the solution is add DragulaModule in the module's xxx.module.tsfile.In this given case you will have to add in the dragula module's dragula.module.tsfile.

Note: when import DragulaModule the path to the ng2-dragula/ng2-dragula may differ depending on your project structure.

Upvotes: 0

Mavlarn
Mavlarn

Reputation: 3883

try to import DragulaModule in you app module(top level module)

Upvotes: 1

Related Questions