[英]What's correct file path in Angular2?
I have a file structure like this : 我有一个像这样的文件结构:
/root
--/app
----app.ts
--/components
----/banner
------banner.ts
------banner.css
--index.html
I have import banner.ts inside app.ts like this import {Banner} from '../components/banner/banner';
我在app.ts中导入了banner.ts,例如import {Banner} from '../components/banner/banner';
In banner.ts, I want to get the banner.css file so I write this: 在banner.ts中,我想获取banner.css文件,所以我这样写:
import {Component} from 'angular2/core';
@Component({
selector: 'banner',
templateUrl: '../components/banner/banner.html',
styleUrls: ['../components/banner/banner.css']
})
This works, but when I change to this, it failed: 这有效,但是当我更改为它时,它失败了:
styleUrls: ['./banner.css']
I also try styleUrls: ['banner.css']
, failed 我也尝试styleUrls: ['banner.css']
,失败了
Based on my understanding, the './' means in the same directory, but why I get an 404 error? 根据我的理解,“ ./”在同一目录中,但是为什么会出现404错误?
I am using the most updated Angular2 我正在使用最新的Angular2
Yes, Only a proper relative file path will be recognized by Angular2 currently. 是的,Angular2当前只能识别正确的相对文件路径。 The Path should actually start from the root like below to be safe, Again we are setting the guidelines from what is working and not working with the beta version, I am sure this is bound to change in the future. 为了安全起见,Path实际上应该从如下所示的根开始。再次,我们根据正在使用的准则来设置准则,而不是在beta版本中起作用,我相信这肯定会在将来发生变化。 But for now, for beta0 the below code is the norm for referencing supplement files for the component. 但就目前而言,对于beta0,以下代码是引用组件补充文件的规范。
import {Component} from 'angular2/core';
@Component({
selector: 'banner',
templateUrl: './app/components/banner/banner.html',
styleUrls: ['./app/components/banner/banner.css']
})
Checkout other large example as well, they all use this pattern. 以及其他大型示例,它们都使用此模式。 A component inside a large Angular2 Sample 大型Angular2样本中的组件
Hi I am happy to see this: 嗨,我很高兴看到这个:
In visual studio 2015 在Visual Studio 2015中
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.