,我认为你是在想着这是一个“ jquery方式“。如果您想对组件中的图像执行操作,则需要将[]添加到要实现的属性。
例如,因为想要动态图像需要应用property bindings,其可以在使用组分作为方法或变量。所以,你可以在图像标签上的方法在src属性添加功能直接
而在组件添加
image(){
//
}
或转让,所以,当动作发生时分配图像输出到图像标签然后将它分配给一个变量
Add
元器件
imageSrc:string = 'http://placehold.it/350x150';
constructor(...){}
onImageUpload(){
let uploadedImage = // get image stuff here
this.imageScr = uploadedImage;
}
没有太多的话题我会建议你为你的输入类型创建一个角度反应形式。这创建了一个更好的结构,其中包含功能烘焙功能,可帮助您实现所需的大部分功能因此,您可以添加一个formControlName而不是一个属性绑定,而您的formGroup将保存所有表单输入值。
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
export class ImagePage{
imageUploadForm: FormGroup;
imagePattern:string = '(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\.(?:jpg|gif|png))(?:\?([^#]*))?(?:#(.*))?'
constructor(public navCtrl: NavController, public navParams: NavParams,
public formBuilder: FormBuilder){
this.imageUploadForm = this.formBuilder.group({
image:['http://placehold.it/350x150',[Validators.required,Validators.pattern(this.imagePattern)]]
imageName:[''[Validators.required]]
})
}
}
,然后在Html
Image is required
Image file must end in .jpg, .png or gif
...
所以现在要在活性形式的formGroup我认为允许更大的灵活性,以及被控制作为formControl功能作为更好定义的一组代码
您可以查看反应形式的官方文档here