简体   繁体   English

core.js:12853 无法绑定到“ngIf”,因为它不是“div”的已知属性

[英]core.js:12853 Can't bind to 'ngIf' since it isn't a known property of 'div'

I am using Angular 9.我正在使用 Angular 9。

and I am having a use case of loading dynamic components我有一个加载动态组件的用例

In one of my component, I am getting the warning在我的一个组件中,我收到了警告

core.js:12853 Can't bind to 'ngIf' since it isn't a known property of 'div' core.js:12853 无法绑定到“ngIf”,因为它不是“div”的已知属性

I have included commonModule in my app.module.ts我在app.module.ts中包含了 commonModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker'
import { HTTP_INTERCEPTORS } from '@angular/common/http';

import { CommonModule } from '@angular/common';

// import { TokenInterceptor } from './auth/token.interceptor';

//Module-imports
import {ServeMonstaAuthenticationRoutingModule} from './serve-monsta-authentication/serve-monsta-authentication-routing.module'
import { ServeMonstaAuthenticationModule } from './serve-monsta-authentication/serve-monsta-authentication.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
//Services-imports
import { UserLoginService } from './serve-monsta-authentication/services/user-login/user-login.service';
import { UserSignupService } from './serve-monsta-authentication/services/user-signup/user-signup.service';
import { SurveyService } from '../services/survey/survey.service';

//Component-imports
import { CreateSurveyComponent } from './components/survey/create-survey/create-survey.component';
import { ViewSurveyComponent } from './components/survey/view-survey/view-survey.component';
import { CreateQuestionsComponent } from './components/questions/create-questions/create-questions.component';
import { PreviewQuestionsComponent } from './components/questions/preview-questions/preview-questions.component';
import { NavbarComponent } from './shared/navbar/navbar.component';
import { SideNavigationComponent } from './shared/side-navigation/side-navigation.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { RadioComponent } from './components/input-components/radio/radio.component';
import { CheckboxComponent } from './components/input-components/checkbox/checkbox.component';
import { DateComponent } from './components/input-components/date/date.component';
import { TextareaComponent } from './components/input-components/textarea/textarea.component';
import { RankingComponent } from './components/input-components/ranking/ranking.component';
import { RatingComponent } from './components/input-components/rating/rating.component';
import { BooleanComponent } from './components/input-components/boolean/boolean.component';
import { ChipDistributionComponent } from './components/input-components/chip-distribution/chip-distribution.component';
import { NumericalComponent } from './components/input-components/numerical/numerical.component';
import { GroupNumberComponent } from './components/input-components/group-number/group-number.component';
import { PlainBannerComponent } from './components/input-components/plain-banner/plain-banner.component';
import { FreeTextComponent } from './components/input-components/free-text/free-text.component';
import { DropdownComponent } from './components/input-components/dropdown/dropdown.component';
import { LongTextComponent } from './components/input-components/long-text/long-text.component';
import { ShortTextComponent } from './components/input-components/short-text/short-text.component';
import { DynamicFieldDirective } from './components/input-components/dynamic-field/dynamic-field.directive';
import { DynamicFormComponent } from './components/questions/dynamic-form/dynamic-form.component';


@NgModule({
  declarations: [
    AppComponent,
    CreateSurveyComponent,
    ViewSurveyComponent,
    CreateQuestionsComponent,
    PreviewQuestionsComponent,
    NavbarComponent,
    SideNavigationComponent,
    DashboardComponent,
    DynamicFieldDirective,
    DynamicFormComponent,
    ],
  imports: [
    BrowserModule,
    CommonModule,
    FormsModule,
    AppRoutingModule,
    ServeMonstaAuthenticationModule,
    ServeMonstaAuthenticationRoutingModule,
    BrowserAnimationsModule,
    RouterModule,
    BsDatepickerModule.forRoot(),
  ],

  entryComponents:[
    RadioComponent,
    CheckboxComponent,
    DateComponent,
    TextareaComponent,
    RankingComponent,
    RatingComponent,
    BooleanComponent,
    ChipDistributionComponent,
    NumericalComponent,
    GroupNumberComponent,
    PlainBannerComponent,
    FreeTextComponent,
    DropdownComponent,
    LongTextComponent,
    ShortTextComponent,
  ],
  providers: [
    // {
    //   provide: HTTP_INTERCEPTORS,
    //   useClass: TokenInterceptor,
    //   multi: true
    // },
    UserLoginService,
    UserSignupService,
    SurveyService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

This is my component where I am using ngIf这是我使用 ngIf 的组件

import { Component, OnInit } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { Field } from '../../../core/question/field';
import { FormGroup } from '@angular/forms';

@Component({
  selector: 'app-radio',
  template: `
    <div class="heightautos" >
      <label class="contatradio">
        <input type="radio" checked="checked" />
        <span class="checkmarkrd"></span>
      </label>
      <input
        type="text"
        name="yes"
        placeholder="Option 1"
        class="optionranking chkleft"
        [value]="field.optionText"
      />
      <div class="attached-closesd ">
        <img
          src="${'../../../../assets/img/icon-close.png'}"
          class=" btn btn-default attached-closebtn"
        />
      </div>
      <div class="attached-closesd ">
        <div class="upload-btn-wrapper">
          <button class="btn borderrt">
            <img src="${'../../../../assets/img/attached.png'}" class="pin" />
          </button>
          <input type="file" name="myfile" />
        </div>
      </div>
      <div class="attached-closesd ">
        <img src="${'../../../../assets/img/perfume.png'}" class="perfume-img" />
      </div>

      <!---other option---->
      <div *ngIf="field.otherOptionAvailable">
        <input 
          type="text"
          placeholder="Other Option {{field.optionId}}"
          class="optioncheck chkleft"
        />
      </div>
      <!---other option---->
    </div>
  `,
  styles: [],
})
export class RadioComponent implements OnInit {
  field: Field;
  group: FormGroup;

  constructor() {}

  ngOnInit(): void {
    console.log("Hey I am Radio :: ", this.field)
  }
}

and here is the object(response) I am getting in my above component这是我在上面的组件中得到的对象(响应)

surveyQuestionResponseBeans: Array(5)
0:
isHavingMultimedia: true
isMandatory: true
isRandomized: true
languageCode: "en"
orderNumber: 1
pageNumber: 1
questionId: 1
questionStatus: "ACTIVE"
questionText: "What is your favourite game?"
questionType: "RADIO"
surveyOptionResponseBeans: (2) [{…}, {…}]
__proto__: Object
1:
isHavingMultimedia: true
isMandatory: true
isRandomized: true
languageCode: "en"
orderNumber: 1
pageNumber: 1
questionId: 2
questionStatus: "ACTIVE"
questionText: "What is your FAV Cuisine.?"
questionType: "CHECKBOX"
surveyOptionResponseBeans: (3) [{…}, {…}, {…}]
__proto__: Object

Any Suggestions I have already included CommonModule and also tried using an extra boolean variable.任何建议我已经包含了 CommonModule 并且还尝试使用额外的 boolean 变量。

If you are using a custom module then you need to import the Common Module there too.如果您使用的是自定义模块,那么您也需要在那里导入通用模块。 Doing so will hopefully resolve this issue.这样做有望解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在控制台中出现错误无法绑定到“ngif”,因为它不是 angular 应用程序中“div”的已知属性 - Getting error in console Can't bind to 'ngif' since it isn't a known property of 'div' in angular app NG0303:无法绑定到“ngif”,因为它不是“div”的已知属性 - NG0303: Can't bind to 'ngif' since it isn't a known property of 'div' 无法绑定到“ useStickyClasses”,因为它不是“ div”的已知属性 - Can't bind to 'useStickyClasses' since it isn't a known property of 'div' 无法绑定 'ngIf' 它不是 'button' 的已知属性 - Can't bind 'ngIf' it isn't a known property of 'button' 无法绑定到“数据集”,因为它不是“画布”的已知属性 - Can't bind to 'datasets' since it isn't a known property of 'canvas' 无法绑定,因为它不是选择器组件的已知属性 - Can't bind to since it isn't a known property of selector component 无法绑定到“”,因为它不是“ angular 2”的已知属性 - can't bind to '' since it isn't a known property of '' angular 2 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“matMenuTrigger”,因为它不是“a”的已知属性 - Can't bind to 'matMenuTrigger' since it isn't a known property of 'a'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM