模态和输入类型文件角
我为个人项目(社交网络)工作。用户可以创建,修改ET删除帖子,他们可以评论我
在Angular上工作的
每篇文章,我有一个显示帖子的后列表组件。 我创建一个打开模态以显示表单以
displayForm() {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.width = "600px";
dialogConfig.maxWidth = "80%";
this.dialog.open(FormPostComponent, dialogConfig);
}
在FormPostComponent的html上创建帖子的finction,如果用户要上传图像,我有一个输入类型文件,
<div>
<label for="file" class="label-file " id="label">Ou choisir une image</label>
<input
#fileinput
type="file"
class="input-file"
id="file"
formControlName="file"
(change)="addFile($event)"
/>
</div>
问题是我无法访问该文件,文件,文件似乎是由模式背后的另一个输入来检索的。
我在我的ModalCompononent中找到了一个带有设置的解决方案:endapsulation:viewScapsulation.shadowdom,但我不认为这是解决方案,因为所有浏览器不支持Shadowdom
@Component({
selector: "app-form-post",
templateUrl: "./form-post.component.html",
styleUrls: ["./form-post.component.scss"],
encapsulation: ViewEncapsulation.ShadowDom,
})
输入更改的路径
谢谢您
i work for a personal project (a social network). Users can create, modify et delete Post and they can comment each post
I work on Angular
I have a post-list component which display posts.
I create a fonction to open a modal to display a Form to create a post
displayForm() {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.width = "600px";
dialogConfig.maxWidth = "80%";
this.dialog.open(FormPostComponent, dialogConfig);
}
On the Html of FormPostComponent i have an input type File if the user want to upload an image
<div>
<label for="file" class="label-file " id="label">Ou choisir une image</label>
<input
#fileinput
type="file"
class="input-file"
id="file"
formControlName="file"
(change)="addFile($event)"
/>
</div>
The problem is i can't have access to the file, the file seems to be retrieved by another input behind the modal.
I find a solution with set in my modalCompononent : encapsulation : ViewEncapsulation.ShadowDom but i don't think it's the solution because ShadowDom is not supported with all the browsers
@Component({
selector: "app-form-post",
templateUrl: "./form-post.component.html",
styleUrls: ["./form-post.component.scss"],
encapsulation: ViewEncapsulation.ShadowDom,
})
the path of the input change
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它嵌套在目标元素属性中。
这是更干净的。直接传递输入元素:
并检索它:
It's nested in the target element property.
This is cleaner. Pass on the input element directly:
and retrieve it: