小编Mig*_*ger的帖子

Angular 5如何从类型=文件的输入中获取文件名

我知道有类似的问题,但没有一个涵盖Angular 5的方法,或者至少没有以我理解的方式涵盖。

对于我的图像上传系统,我需要知道是否在输入标签上附加了图片以及文件的名称。这是我的代码:

HTML:

<input 
  type="file" 
  [(ngModel)]="currentInput"
  (change)="onFileSelected($event)"
>
Run Code Online (Sandbox Code Playgroud)

角度:

export class ImageUpload {
    currentInput;

    onFileSelected(event) {
        console.log(this.currentInput);
    }
}
Run Code Online (Sandbox Code Playgroud)

无论是否附加文件,“ currentInput”中的值始终是不确定的。当类型等于“文件”时,如何处理输入?

谢谢!

image input ngmodel angular

4
推荐指数
2
解决办法
6995
查看次数

如何在[(ngModel)]中使用Map()?

我正试图在特定键的地图中获取特定值.

在我的代码中,我ngFor用来遍历数组.我在每次迭代中得到的项应该是地图的关键值,而用户输入相应的值.

重要信息:该变量userInputValue不存在.这就是我的问题:如何获得,userInputValue以便我可以将它应用到地图上?我希望你能不知道我的意思..

item是例如任何字符串"Name"userInputValue将任何用户键入到input field,我如何才能在这种情况下,后者的?

在我的Component.html中

<form *ngFor="let item of myStringArray">
    <input [(ngModel)]="map.set(item, userInputValue)">
</form>
Run Code Online (Sandbox Code Playgroud)

在我的Component.ts中

public map = new Map<string, string>();

public myMethod() {
    this.stringInputs.forEach((item) => {
       this.eintrag.raumgroesseQM = this.map.get(item);
    });
}
Run Code Online (Sandbox Code Playgroud)

是否有可能以这种方式使用Map,如果是的话,我怎么能正确地做到,如果没有,有没有其他方法可以达到这个目标(当然除了自己上课)?

我当前的方法使用分隔符拆分,如下所示:

// the string would be something like: "Name;34"

this.finalInputWithContext.forEach((item) => {

  if (item.split(";")[0] === "Name") {
    concole.log(item.split(";")[1]); // will print 34
  }

});
Run Code Online (Sandbox Code Playgroud)

这个解决方案当然也有效,但我被告知使用地图代替..

typescript angular

4
推荐指数
1
解决办法
874
查看次数

Angular,如何将变量用于 iframe 源?

我想使用来自 youtube 和其他类似平台的 iframe - 但我不知道如何使用变量作为我的源。

我已经搜索过了,但我得到的答案没有奏效。

所以这里是 iframe:

<div class="right">
    <h2>Associated Pictures/Media Files</h2>
    <p>Here we will display either Infos, Fotos, Videos, Music or even interative content.</p>
    <div style="padding: 2%;">
        <iframe 
        width="100%" 
        height="315" 
        src="https://www.youtube.com/embed/Q7hmXN714RQ" 
        frameborder="0" 
        allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" 
        allowfullscreen>
        </iframe>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我唯一想要的是在这里使用这个变量:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  source = 'https://www.youtube.com/embed/Q7hmXN714RQ';
}       
Run Code Online (Sandbox Code Playgroud)

但是当我尝试以各种方式做到这一点时 - 例如:

src="{{source}}"
Run Code Online (Sandbox Code Playgroud)

这根本不起作用:(

有谁知道如何正确地做到这一点?我找不到针对此问题的适当解决方案。

html angular

1
推荐指数
1
解决办法
3141
查看次数

标签 统计

angular ×3

html ×1

image ×1

input ×1

ngmodel ×1

typescript ×1