In my js file, I have a function that displays the users data on the screen, but for some reason, that is what prevents the data being saved to the database. I want to have both, so without the js file, it saves it to the database.
Edit: What I am basically trying to do is upload the clients entered content on screen permanently so other clients will be able to see it all while saving it to the database. But my issue is that my js script is preventing the clients content from being saved to the database. I am new to angular, but I would very much appreciate it if someone can provide an example using $http.post, if that would help what I am asking for.
Edit: I kind of found my problem, but I have not solved it fully. The ng-click from the button element was preventing the clients data from being saved to the db, but now the button after submission is enabled, resulting in submitting many forms. How can I approach this? I am fairly new to this site, so does this change my question?
HTML
<form action="/blog" method="POST">
<div id="textarea-format-structure">
<textarea name="dummyInfo" id="blogVal" ng-model="textAreaValue"
ng-change="textChange()" ng-focus="btnChange = true" />
</div>
<button ng-disabled="btnChange" ng-click="btnChange = true" class="btnpost">Post</button>
</form>
<div id="my-posts-blog"></div>
JS
function postVal() {
var blogVal = document.getElementById("blogVal");
var appendVal = document.getElementById("my-posts-blog");
var create_div = document.createElement("div");
create_div.textContent = blogVal.value;
create_div.classList.add("post");
appendVal.prepend(create_div);
blogVal.value = "";
}
document.getElementById("blogVal").focus();
var postIt = document.querySelector(".btnpost");
postIt.addEventListener("click", postVal, false);
NODE.JS
router.post("/blog", (req, res) => {
mongo.connect(url, { useNewUrlParser: true }, (err, client) => {
var db = client.db("test");
db.collection("collect").insertOne({ myBlog: req.body.dummyInfo});
});
});