Angular Popup组件不允许访问confirmNo / confirmYes

时间:2019-11-30 22:40:22

标签: angular typescript

我有一个带有一些文本的弹出组件和一个单击处理程序,在我进行开发时(例如ng build),该处理程序可以很好地工作。但是,当我在生产环境(即ng build --prod)中进行构建时,出现以下错误:

ERROR in node_modules/ng2-opd-popup/components/popup/popup.component.html(9,76): Property 'confirmNo' is private and only accessible within class 'PopupComponent'.
node_modules/ng2-opd-popup/components/popup/popup.component.html(10,66): Property 'confirmYes' is private and only accessible within class 'PopupComponent'.

我遵循了Readme中的指南,但没有建立。

这是我的app.module.ts的样子: ... 从'ng2-opd-popup'导入{PopupModule};

@NgModule({
  declarations: [
    ...
  ],
  entryComponents: [
    ...
  ],
  imports: [
    ...,
    PopupModule
  ],
  providers: [{
    ......
  }, ...],
  bootstrap: [AppComponent],
  exports: [
   ...
  ]
})
export class AppModule { }

这是组件:

import { Popup } from 'ng2-opd-popup';


@Component( {
  selector: 'app-admin',
  templateUrl: './admin.component.html',
  styleUrls: [ './admin.component.scss' ]
} )
export class AdminComponent implements OnInit
{

  constructor ( public popup: Popup ) { }

  ngOnInit ()
  {

  }

  act() {
    alert('WORKS');
  }

  show() {


      this.popup.options = {
        header: 'TEST',
        confirmBtnContent: 'Yes',
        cancleBtnContent: 'No',
        confirmBtnClass: 'btn btn-default',
        cancleBtnClass: 'btn btn-default',
        animation: 'fadeInDown'
    };
      this.popup.show(this.popup.options);
  }

}

这是HTML文件


<h1>Test</h1>

        <button (click)="show()">Show</button>  

        <popup (confirmClick)='act()'>Are you sure you?</popup>

1 个答案:

答案 0 :(得分:0)

如果要使用提前编译,则不能访问模板中的私有成员:由其模板访问的组件中的所有方法和属性在编译场景中必须是公共的,因此请尝试声明ConfirmNo和我想确认是否是您的弹出窗口组件或show方法中的公共属性。 有关编译器错误处理私有属性Here

的更多详细信息
相关问题