相关疑难解决方法(0)

Angular2 - 应该在模板中访问私有变量吗?

如果private在组件类上声明了变量,我是否应该能够在该组件的模板中访问它?

@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>{{title}}</h2>
      <h2>Hello {{userName}}</h2> // I am getting this name
    </div>
  `,
})
export class App {
  public title = 'Angular 2';
  private userName = "Test Name"; //declared as private
}
Run Code Online (Sandbox Code Playgroud)

typescript angular2-template angular

127
推荐指数
4
解决办法
5万
查看次数

Angular 2/4/5 - 提前编译如何

我正在尝试按照本指南https://angular.io/docs/ts/latest/guide/ngmodule.html引导我的Angular 2 RC5应用程序. 下面是我的代码

import { AppModuleNgFactory } from './app.module.ngfactory';
import {platformBrowser} from "@angular/platform-browser";

platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试编译打字稿代码时,我收到以下错误

app\main.ts(1,36):错误TS2307:找不到模块'./app.module.ngfactory'.

如何生成app.module.ngfactory文件?我应该使用哪种工具?

typescript angular

40
推荐指数
2
解决办法
3万
查看次数

AoT NGC/Angular2:属性受到保护,只能在类Error中访问

在我使用的Angular 2/Ionic 2(final/rc0)项目中的组件中:

protected contentTarget: ViewContainerRef;

ngOnInit() {
        this.contentTarget.createComponent(componentFactory);
    }
Run Code Online (Sandbox Code Playgroud)

AoT编译器说:

Error at ....: Property 'contentTarget' is protected and only accessible within class 'IncludeTemplateComponent' and its subclasses.
Run Code Online (Sandbox Code Playgroud)

变量(属性)不会在整个项目中的任何其他位置使用.

那么......任何人都可以对此有所了解,是createComponent工厂将contentTarget变量传递给它的子节点,或者为什么编译器不喜欢这里受保护?现在所有Angular2中的受保护变量都是"被禁止的"吗?

ionic2 angular

7
推荐指数
1
解决办法
2709
查看次数

标签 统计

angular ×3

typescript ×2

angular2-template ×1

ionic2 ×1