我正在Angular 6上开发一个应用程序,并且在我的本地开发环境上运行良好,但是当我尝试使用ng build --prod
6应用程序构建Angular时,会抛出错误。
Home.Component.ts 从'@ angular / core'导入{Component,OnInit};
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
src: HTMLImageElement;
constructor() { }
ngOnInit() {
}
}
Home.component.html
<section class="featured-lis">
<div class="container padding_zero">
<div class="row">
<div class="col-md-12">
<div class="jumbotron custom_ads">
<img [src]="src/assets/images/ads/ad1.png" alt="">
</div>
</div>
</div>
</div>
</section>
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
<div class="single-cta">
<div class="cta-icon">
<i class="lni-grid"></i>
</div>
<h4>Refreshing Design</h4>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie</p>
</div>
</div>
<div class="col-xs-12 col-md-6 col-lg-4">
<div class="single-cta">
<div class="cta-icon">
<i class="lni-brush"></i>
</div>
<h4>Easy to Customize</h4>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie</p>
</div>
</div>
<div class="col-xs-12 col-md-6 col-lg-4">
<div class="single-cta">
<div class="cta-icon">
<i class="lni-headphone-alt"></i>
</div>
<h4>24/7 Support</h4>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie</p>
</div>
</div>
</div>
</div>
</section>
<app-footer></app-footer>
答案 0 :(得分:0)
如果您尝试访问未正确声明的类的属性,则可能会发生此类错误。
例如,如果您有这样的组件(简化了语法):
export class HomeComponent implements OnInit {
constructor() {}
ngOninit() {}
}
在您的component.html文件中,您尝试访问一些未声明的属性,例如:
<div>{{ads}}</div>
它不会让您正确构建项目。
要解决此问题,请声明您在组件类中使用的所有属性:
export class HomeComponent implements OnInit {
ads: any;
src: any;
assets: any; // and other....
constructor() {}
ngOninit() {}
... further code of your component
}
答案 1 :(得分:0)
更改
<img [src]="src/assets/images/ads/ad1.png" alt="">
到
<img [src]="'src/assets/images/ads/ad1.png'" alt="">
甚至
<img src="src/assets/images/ads/ad1.png" alt="">
以及所有类似的问题。