Image is not getting render in angular firebase












0














I am uploading image from my local machine and storing on firebase and generating downloadUrl, with that download url i want to render the image with src tag on the same page but the image is not rendering here is my code for uploading image:-



<div class="form-group">
<label for="image">Image</label>
<input #imageurl="ngModel" [(ngModel)]="imagedetails" name="imageurl" id="imageurl" type="file" (change)="onselected($event)" class="form-control" required>
<div class="alert alert-danger" *ngIf="imageurl.touched && imageurl.invalid">
Invalid Image Url

</div>
</div>

<!--Save Button-->
<button class="btn btn-primary">Save</button>
</form>
</div>

</div>
<div class="col-md-6">
<div class="card" style="width: 18rem;">
{{downloadUrl}}
<img class="card-img-top" [src]="downloadUrl" >
<div class="card-body">
<h5 class="card-title">{{title.value}}</h5>
<p class="card-text">{{price.value}}</p>
</div>
</div>
</div>

</div>


In my component.ts i wam generating downloadUrl and setting that downloadUrl to src tag below is my component.ts:-



  onselected(event)
{
console.log("The Select File is",event.target.files[0]);
let name=event.target.files[0];
console.log("THe Name is",name.name);
const metadata={'contentType':name.type};
let url1="url3";
const storageRef:firebase.storage.Reference=firebase.storage().ref('/images/feature/'+url1);
storageRef.put(name,metadata);
storageRef.getDownloadURL().then(downloadURL => {
const imageUrl = downloadURL;
this.downloadUrl=imageUrl;
console.log('URL:' + imageUrl);
})

}
save(product)
{
console.log("The Catagory",this.catagoryData);
console.log("The ImageData is",this.imagedetails);
product.imageUrl=this.downloadUrl;
product.url=this.downloadUrl;
console.log("The Prodcut is",product);
this.catagory.createProduct(product);

}


Please help to solve issue how i can display image as soon as i upload it on to the form










share|improve this question





























    0














    I am uploading image from my local machine and storing on firebase and generating downloadUrl, with that download url i want to render the image with src tag on the same page but the image is not rendering here is my code for uploading image:-



    <div class="form-group">
    <label for="image">Image</label>
    <input #imageurl="ngModel" [(ngModel)]="imagedetails" name="imageurl" id="imageurl" type="file" (change)="onselected($event)" class="form-control" required>
    <div class="alert alert-danger" *ngIf="imageurl.touched && imageurl.invalid">
    Invalid Image Url

    </div>
    </div>

    <!--Save Button-->
    <button class="btn btn-primary">Save</button>
    </form>
    </div>

    </div>
    <div class="col-md-6">
    <div class="card" style="width: 18rem;">
    {{downloadUrl}}
    <img class="card-img-top" [src]="downloadUrl" >
    <div class="card-body">
    <h5 class="card-title">{{title.value}}</h5>
    <p class="card-text">{{price.value}}</p>
    </div>
    </div>
    </div>

    </div>


    In my component.ts i wam generating downloadUrl and setting that downloadUrl to src tag below is my component.ts:-



      onselected(event)
    {
    console.log("The Select File is",event.target.files[0]);
    let name=event.target.files[0];
    console.log("THe Name is",name.name);
    const metadata={'contentType':name.type};
    let url1="url3";
    const storageRef:firebase.storage.Reference=firebase.storage().ref('/images/feature/'+url1);
    storageRef.put(name,metadata);
    storageRef.getDownloadURL().then(downloadURL => {
    const imageUrl = downloadURL;
    this.downloadUrl=imageUrl;
    console.log('URL:' + imageUrl);
    })

    }
    save(product)
    {
    console.log("The Catagory",this.catagoryData);
    console.log("The ImageData is",this.imagedetails);
    product.imageUrl=this.downloadUrl;
    product.url=this.downloadUrl;
    console.log("The Prodcut is",product);
    this.catagory.createProduct(product);

    }


    Please help to solve issue how i can display image as soon as i upload it on to the form










    share|improve this question



























      0












      0








      0







      I am uploading image from my local machine and storing on firebase and generating downloadUrl, with that download url i want to render the image with src tag on the same page but the image is not rendering here is my code for uploading image:-



      <div class="form-group">
      <label for="image">Image</label>
      <input #imageurl="ngModel" [(ngModel)]="imagedetails" name="imageurl" id="imageurl" type="file" (change)="onselected($event)" class="form-control" required>
      <div class="alert alert-danger" *ngIf="imageurl.touched && imageurl.invalid">
      Invalid Image Url

      </div>
      </div>

      <!--Save Button-->
      <button class="btn btn-primary">Save</button>
      </form>
      </div>

      </div>
      <div class="col-md-6">
      <div class="card" style="width: 18rem;">
      {{downloadUrl}}
      <img class="card-img-top" [src]="downloadUrl" >
      <div class="card-body">
      <h5 class="card-title">{{title.value}}</h5>
      <p class="card-text">{{price.value}}</p>
      </div>
      </div>
      </div>

      </div>


      In my component.ts i wam generating downloadUrl and setting that downloadUrl to src tag below is my component.ts:-



        onselected(event)
      {
      console.log("The Select File is",event.target.files[0]);
      let name=event.target.files[0];
      console.log("THe Name is",name.name);
      const metadata={'contentType':name.type};
      let url1="url3";
      const storageRef:firebase.storage.Reference=firebase.storage().ref('/images/feature/'+url1);
      storageRef.put(name,metadata);
      storageRef.getDownloadURL().then(downloadURL => {
      const imageUrl = downloadURL;
      this.downloadUrl=imageUrl;
      console.log('URL:' + imageUrl);
      })

      }
      save(product)
      {
      console.log("The Catagory",this.catagoryData);
      console.log("The ImageData is",this.imagedetails);
      product.imageUrl=this.downloadUrl;
      product.url=this.downloadUrl;
      console.log("The Prodcut is",product);
      this.catagory.createProduct(product);

      }


      Please help to solve issue how i can display image as soon as i upload it on to the form










      share|improve this question















      I am uploading image from my local machine and storing on firebase and generating downloadUrl, with that download url i want to render the image with src tag on the same page but the image is not rendering here is my code for uploading image:-



      <div class="form-group">
      <label for="image">Image</label>
      <input #imageurl="ngModel" [(ngModel)]="imagedetails" name="imageurl" id="imageurl" type="file" (change)="onselected($event)" class="form-control" required>
      <div class="alert alert-danger" *ngIf="imageurl.touched && imageurl.invalid">
      Invalid Image Url

      </div>
      </div>

      <!--Save Button-->
      <button class="btn btn-primary">Save</button>
      </form>
      </div>

      </div>
      <div class="col-md-6">
      <div class="card" style="width: 18rem;">
      {{downloadUrl}}
      <img class="card-img-top" [src]="downloadUrl" >
      <div class="card-body">
      <h5 class="card-title">{{title.value}}</h5>
      <p class="card-text">{{price.value}}</p>
      </div>
      </div>
      </div>

      </div>


      In my component.ts i wam generating downloadUrl and setting that downloadUrl to src tag below is my component.ts:-



        onselected(event)
      {
      console.log("The Select File is",event.target.files[0]);
      let name=event.target.files[0];
      console.log("THe Name is",name.name);
      const metadata={'contentType':name.type};
      let url1="url3";
      const storageRef:firebase.storage.Reference=firebase.storage().ref('/images/feature/'+url1);
      storageRef.put(name,metadata);
      storageRef.getDownloadURL().then(downloadURL => {
      const imageUrl = downloadURL;
      this.downloadUrl=imageUrl;
      console.log('URL:' + imageUrl);
      })

      }
      save(product)
      {
      console.log("The Catagory",this.catagoryData);
      console.log("The ImageData is",this.imagedetails);
      product.imageUrl=this.downloadUrl;
      product.url=this.downloadUrl;
      console.log("The Prodcut is",product);
      this.catagory.createProduct(product);

      }


      Please help to solve issue how i can display image as soon as i upload it on to the form







      angular






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 7:18









      georgeawg

      32.5k104967




      32.5k104967










      asked Nov 13 at 3:32









      Sam

      65




      65





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273400%2fimage-is-not-getting-render-in-angular-firebase%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273400%2fimage-is-not-getting-render-in-angular-firebase%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)