Whats equivalent to ngSrc in the newer Angular?

后端 未结 4 665
我在风中等你
我在风中等你 2020-12-13 23:18

I would like to implement img, with a src coming from JSON object.

In AngularJS, I could do:

\"Description\"
         


        
4条回答
  •  星月不相逢
    2020-12-13 23:41

    It is a two-step process to achieve the same functionality of ng-src in your Angular application.

    First Step:

    In your HTML, use the new syntax:

    Second Step:

    In your component/directive, initialize the value to be empty. For example:

    @Component({
      selector: 'ag-video',
      templateUrl: './video.component.html'
    })
    export class SampleComponent {
       imageSrc = '';
    }
    

    Now, this would eliminate the null network call (empty call) due to the value not being set on to the element.

提交回复
热议问题