简体   繁体   English

如何在 Angular 7 项目中集成 html 模板

[英]how to integrate a html template in angular 7 project

I'm integrating a html template in angular 7 project and it is not working correctly我在 Angular 7 项目中集成了一个 html 模板,但它无法正常工作

I added the template files under assets/template/.. and i added the imports in angular.json like:我在 assets/template/.. 下添加了模板文件,并在 angular.json 中添加了导入,例如:

  • "styles": ["src/assets/template/css/style-customizer.css",...], “样式”:[“src/assets/template/css/style-customizer.css”,...],
  • "scripts": ["src/assets/template/js/vendor/modernizr-2.8.3.min.js",...] “脚本”:[“src/assets/template/js/vendor/modernizr-2.8.3.min.js”,...]

I edited the html code:我编辑了html代码:

  • removed doctype and html tags删除了 doctype 和 html 标签
  • removed all the header删除了所有标题
  • removed all css and js imports删除了所有 css 和 js 导入
  • edited the images sources编辑图像源

(like src="/assets/template/img/slider/1.jpg" alt="main slider" title="#htmlcaption1") (比如 src="/assets/template/img/slider/1.jpg" alt="main slider" title="#htmlcaption1")

I added the html code in index.html under the app-root tag and all working fine我在 index.html 的 app-root 标签下添加了 html 代码,一切正常

But when i change it to app.component.html:但是当我将它更改为 app.component.html 时:

  • some images not showing一些图像不显示
  • some css are not working correctly某些 CSS 无法正常工作
  • and some animations not working和一些动画不工作

and I don't have any error in my console我的控制台没有任何错误

I usually don't use styles array in angular.json, Instead, I import all global styles in styles.css as it is set into angular.json styles array by default.我通常不在 angular.json 中使用样式数组,而是在 styles.css 中导入所有全局样式,因为它默认设置为 angular.json 样式数组。

/* You can add global styles to this file, and also import other style files */

@import "assets/quote.css";

@import "https://fonts.googleapis.com/css?family=IBM+Plex+Sans+Condensed:200|Josefin+Sans:300|Julius+Sans+One|Merriweather+Sans:400|Overpass:400|Quicksand"

Just add encapsulation: ViewEncapsulation.None in @component like below mentioned.只需在 @component 中添加encapsulation: ViewEncapsulation.None @component所述。

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
    encapsulation: ViewEncapsulation.None
})

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM