【问题标题】:how to change image dynamically in angular 4如何以角度4动态更改图像
【发布时间】:2017-08-02 05:35:55
【问题描述】:
export class AppComponent {
  title = 'app';    
  bttnclick(){    
     var a;
     a=(<HTMLInputElement>document.getElementById('browse1')).value    
     console.log(a);        //contains the name of image
     (<HTMLInputElement>document.getElementById('image2')).value=a;
  }
}

我是这个领域的初学者,我想通过改变浏览框中的值来改变图像源。

【问题讨论】:

    标签: html angular material-design


    【解决方案1】:

    连接两个兄弟的最简单方法是使用模板变量(如#input 这里:

    <input #input>
    <img src="/my/path/{{input.value}}">
    

    【讨论】:

    • 我的 html 是 ..
      第一个分配
    • 缺少模板变量&lt;input id=image1 #image1
    • 但仍然无法正常工作....实际上我正在处理角度 4 .. 当我检查路径时,即采用“localhost:4200/home/pratap/Desktop/pratap/New%20Volume/pratap/…”这条路径
    • 预期路径是什么?
    • 确切位置是 /home/pratap/Desktop/pratap/New%20Volume/pratap/Camera/home/img002.jpeg
    猜你喜欢
    • 2018-03-20
    • 2019-04-10
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多