eni*_*tor 4 node.js express angular
我在显示来自我的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);
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
解!
对于有此问题的任何人,请确保在image source属性中提供的地址后面加上“ http://”,因为在我的情况下,我没有附加它。这为我解决了问题,现在它就像一个魅力!
你url必须有点像这样的: “ HTTP://本地主机:3000 /资产/图像/上传/ c91a3649fc432040e54b9179a72539ad1530343409773.png ”
令人困惑的部分实际上是,当您在浏览器的url中编写它(没有http://)时,它会自动附加它而不通知我们,但是Angular并非如此,您必须显式编写它。编码愉快。我希望这对某人有帮助,因为我花了14个小时才弄清楚。
归档时间: |
|
查看次数: |
3106 次 |
最近记录: |