ng-tags-input get name and catch it from server req.body

167 views Asked by At

Hey i dont know how to get ng-tags-input name and then catch it from the server on request.body its just not there

template html (there are more labels but the others works fine there are inputs and textarea i put only one that works and the tags-input is that doesn't work)

<form action="/projects" method='POST'>
  <label>Title</label>
  <input type="text" name="title" ng-model="title" placeholder="Your title">
  <tags-input use-strings="true" ng-model="tags" display-property="tags" placeholder="Add a Tag"></tags-input>
  <input class="btn btn-primary" type="submit" value="Start new project">
</form>

server

const Project = require('../../../models/project')

function addProject (req, res) {
const { title } = req.body
console.log(req.body)

const project = new Project({ title })

project.save()
.then(() => res.redirect('/app/#!/start-project'))

}

module.exports = addProject

Thats the console.log with the req.body:image log

If its needed something else say me it's my first post and im just learning thanks!

2

There are 2 answers

2
Maxim Shoustin On

From github issues I think the workaround is to add ng-submit="submit()" to your form:

  $scope.submit = function(){
    var tagObjectArray = $scope.tags;
    var tagIdArray = tagObjectArray.map(function(obj){
        return obj.id;
    });

  };
});
0
Marc vergara On

I solve the this problem if somebody arrives here. That is I do is to send the POST from ng-submit() and all input camps are in the $scope and send it trought angular petition