Simple javascript not working in Ionic 3 when viewing on localhost












0














I am trying to get some really simple javascript to work in an ionic 3 app. This js code works fine when I serve it to local host as a stand alone html file. But when rendered with ionic, it is not working. Any advice?



<ion-content padding> 

<div>
<div class="inputoutput">
<img id="imageSrc" alt="No Image" />
<div class="caption">imageSrc <input type="file" id="fileInput" name="file" /></div>
</div>
</div>

<script type="text/javascript">
let imgElement = document.getElementById("imageSrc")
let inputElement = document.getElementById("fileInput");
inputElement.addEventListener("change", (e) => {
imgElement.src = URL.createObjectURL(e.target.files[0]);
}, false);
</script>

</ion-content>









share|improve this question


















  • 2




    What do you mean by not working? Any erros displayed ? What is the result ?
    – V. Sambor
    Nov 20 at 23:26












  • When I select an image by browsing to it, the image should show up on the screen. This works as expected when serving as a stand alone html file, but the image does not show up when serving as an ionic app. No errors showing up in the chrome inspect tool
    – tjp
    Nov 20 at 23:38










  • try removing the script tags out of the <ion-content>
    – marvinIsSacul
    Nov 21 at 4:54
















0














I am trying to get some really simple javascript to work in an ionic 3 app. This js code works fine when I serve it to local host as a stand alone html file. But when rendered with ionic, it is not working. Any advice?



<ion-content padding> 

<div>
<div class="inputoutput">
<img id="imageSrc" alt="No Image" />
<div class="caption">imageSrc <input type="file" id="fileInput" name="file" /></div>
</div>
</div>

<script type="text/javascript">
let imgElement = document.getElementById("imageSrc")
let inputElement = document.getElementById("fileInput");
inputElement.addEventListener("change", (e) => {
imgElement.src = URL.createObjectURL(e.target.files[0]);
}, false);
</script>

</ion-content>









share|improve this question


















  • 2




    What do you mean by not working? Any erros displayed ? What is the result ?
    – V. Sambor
    Nov 20 at 23:26












  • When I select an image by browsing to it, the image should show up on the screen. This works as expected when serving as a stand alone html file, but the image does not show up when serving as an ionic app. No errors showing up in the chrome inspect tool
    – tjp
    Nov 20 at 23:38










  • try removing the script tags out of the <ion-content>
    – marvinIsSacul
    Nov 21 at 4:54














0












0








0







I am trying to get some really simple javascript to work in an ionic 3 app. This js code works fine when I serve it to local host as a stand alone html file. But when rendered with ionic, it is not working. Any advice?



<ion-content padding> 

<div>
<div class="inputoutput">
<img id="imageSrc" alt="No Image" />
<div class="caption">imageSrc <input type="file" id="fileInput" name="file" /></div>
</div>
</div>

<script type="text/javascript">
let imgElement = document.getElementById("imageSrc")
let inputElement = document.getElementById("fileInput");
inputElement.addEventListener("change", (e) => {
imgElement.src = URL.createObjectURL(e.target.files[0]);
}, false);
</script>

</ion-content>









share|improve this question













I am trying to get some really simple javascript to work in an ionic 3 app. This js code works fine when I serve it to local host as a stand alone html file. But when rendered with ionic, it is not working. Any advice?



<ion-content padding> 

<div>
<div class="inputoutput">
<img id="imageSrc" alt="No Image" />
<div class="caption">imageSrc <input type="file" id="fileInput" name="file" /></div>
</div>
</div>

<script type="text/javascript">
let imgElement = document.getElementById("imageSrc")
let inputElement = document.getElementById("fileInput");
inputElement.addEventListener("change", (e) => {
imgElement.src = URL.createObjectURL(e.target.files[0]);
}, false);
</script>

</ion-content>






javascript ionic3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 23:23









tjp

113




113








  • 2




    What do you mean by not working? Any erros displayed ? What is the result ?
    – V. Sambor
    Nov 20 at 23:26












  • When I select an image by browsing to it, the image should show up on the screen. This works as expected when serving as a stand alone html file, but the image does not show up when serving as an ionic app. No errors showing up in the chrome inspect tool
    – tjp
    Nov 20 at 23:38










  • try removing the script tags out of the <ion-content>
    – marvinIsSacul
    Nov 21 at 4:54














  • 2




    What do you mean by not working? Any erros displayed ? What is the result ?
    – V. Sambor
    Nov 20 at 23:26












  • When I select an image by browsing to it, the image should show up on the screen. This works as expected when serving as a stand alone html file, but the image does not show up when serving as an ionic app. No errors showing up in the chrome inspect tool
    – tjp
    Nov 20 at 23:38










  • try removing the script tags out of the <ion-content>
    – marvinIsSacul
    Nov 21 at 4:54








2




2




What do you mean by not working? Any erros displayed ? What is the result ?
– V. Sambor
Nov 20 at 23:26






What do you mean by not working? Any erros displayed ? What is the result ?
– V. Sambor
Nov 20 at 23:26














When I select an image by browsing to it, the image should show up on the screen. This works as expected when serving as a stand alone html file, but the image does not show up when serving as an ionic app. No errors showing up in the chrome inspect tool
– tjp
Nov 20 at 23:38




When I select an image by browsing to it, the image should show up on the screen. This works as expected when serving as a stand alone html file, but the image does not show up when serving as an ionic app. No errors showing up in the chrome inspect tool
– tjp
Nov 20 at 23:38












try removing the script tags out of the <ion-content>
– marvinIsSacul
Nov 21 at 4:54




try removing the script tags out of the <ion-content>
– marvinIsSacul
Nov 21 at 4:54

















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%2f53403121%2fsimple-javascript-not-working-in-ionic-3-when-viewing-on-localhost%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%2f53403121%2fsimple-javascript-not-working-in-ionic-3-when-viewing-on-localhost%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

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'