我无法从我的node.js(快速服务器)localhost:3000 / assets / images / uploads显示图像。当我在浏览器中输入此URL时,此方法工作正常,浏览器显示图像,但是当我将其分配给Angular 5应用程序中的变量并使用绑定到时,我得到
无法加载资源:net :: ERR_UNKNOWN_URL_SCHEME。
我附上以下代码。请检查一下。
export class ProfileComponent implements OnInit {
user: any;
url: "";
path: SafeUrl;
public uploader:FileUploader = new FileUploader({url: URL, itemAlias: 'photo'});
constructor(private authService: AuthServiceService,
private userService: UsersService,
private http: Http,
private el: ElementRef,
private _DomSanitizationService: DomSanitizer) {
}
ngOnInit() {
this.user = this.authService.user;
console.log(this.user);
this.path = this._DomSanitizationService.bypassSecurityTrustUrl(this.user.img);
<input type="file" name="photo" ng2FileSelect [uploader]="uploader" />
<!-- button to trigger the file upload when submitted -->
<button type="button" class="btn btn-success btn-s" (click)="uploader.uploadAll()" [disabled]="!uploader.getNotUploadedItems().length">
Upload with ng-2 file uploader
</button>
<div class="user profile">
<div class="ui container">
<div class="ui grid">
<div class="ui five wide column">
<div class="ui card">
<a class="image poping up" href="" id="profile-avatar" data-content="avatar" data-variation="inverted tiny" data-position="bottom center">
<img [src] = "path" target="_blank" title="Hamza"/>
</a>
<div class="content">
<span class="header text center">Hamza</span>
<span class="username text center">Hamza</span>
</div>
<div class="extra content">
<ul class="text black">
<li><i class="octicon octicon-location"></i> Lahore</li>
<li>
<i class="octicon octicon-mail"></i>
<a href="" rel="nofollow">email</a>
</li>
<li><i class="octicon octicon-clock"></i> date</li>
</ul>
</div>
</div>
</div>
<div class="ui eleven wide column">
<div class="ui secondary pointing menu">
<a class="activity">
<i class="octicon octicon-repo"></i> Posts
</a>
<a class="item">
<a class="activity">
<i class="octicon octicon-rss"></i> Top Posts
</a>
</a>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:5)
解决方案!
对于有此问题的任何人,请确保在image source属性中提供的地址后面附加“ http://”,因为在我的情况下,我没有附加它。 这为我解决了问题,现在它就像一个魅力!
您的网址必须是这样的:“ http://localhost:3000/assets/images/uploads/c91a3649fc432040e54b9179a72539ad1530343409773.png”
实际上令人困惑的部分是,当您在浏览器的url中编写它而没有 http:// 时,它会自动附加它而不让我们知道,但这不是如果是Angular,则必须明确地编写它。 编码愉快。 我希望这对某人有帮助,因为我花了14个小时才弄清楚。