1
仍然在我的第一個Angular項目上工作,現在我需要開始使頁面看起來更好一些,並且我想要添加圖像。如何在Angular中顯示圖像
我知道Html它只是簡單的<img src="*">
但角實際上並沒有加載圖像到頁面。
我的組件文件看起來是這樣的:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
styles: ['.container-fluid{ border: 1px solid black; margin: 10px; padding:
10px; border-radius: 20px;}','.qr-image{ width: 100px ;}'],
template: `
<h1> Regional Forum Report Registration</h1>
<div class='container-fluid'>
<form-area></form-area>
</div>
<div class="qr-code">
<h3> Long Line? Scan this code to SignUp!</h3>
<img class='qr-image' alt='Address for Signup Page' [src]="qrpath">
</div>
`
})
export class AppComponent {
this.qrpath = '/app/rf.png';
}
我也通過一些其他的問題看,和我有一些他們的幾個問題。首先,他們爲什麼建議圍繞src
屬性使用方括號?其次,爲什麼我們不能只用src="pathToImg.jpg"
?
進一步的細節,這裏是我的文件夾結構:
它確實足以讓我們問爲什麼它不能用''調用 –
瀏覽器所在位置的圖像是否在?瀏覽器開發工具是什麼意思? –
derp。文件路徑問題。必須記住需要相對於Index.html的路徑.... –