0

I have a form that creates a new object with angularjs. The data is sent back under the name marker.

$scope.createMarker = function() {

    $http.post('/markers/create', $scope.marker)
        .success(function(data) {

        })
        .error(function(data) {
              console.log('Error: ' + data);
        });
    };

So in my markers.ejs, I get the value back :

 <input id="marker"> {{marker}} </input>

But I would like to get it directly in a javascript function :

 console.log({{marker}})

Is it possible ?

For now I have the solution of stocking it into the input and get it with jquery:

     <input id="marker" value="{{marker}}"> </input>

     <script> console.log($("#marker").val()) </script>

But could we directly pass it into the js ?

Thanks for your help !

2 Answers 2

1

AngularJS encourages separation of presentation and controllers. If you intend to use a JS function directly, there is to need to do anything in your .ejs file, which is meant for presentation only.

Therefore, you should call console.log(marker) (or console.log($scope.marker)) directly in your success callback.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ! In this case I will keep it separated. It is good to know that there is a solution, in case.
1

yes you can. Put in the success case something like this

success(data){
    var Mydata=data
}

and out from it

$scope.marker=Mydata

so you can bind the variable to you html element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.