0

I am using AngularJS. I would like to send multiple data in a HTTP post through AngularJS.I am using laravel php as backend and tinymce as my html text editor.The problem is that tinymce comes up with a model and i am unable to figure it out on how to pass data that is dealing with multiple models.

Here is my partial:

<div ng-controller="controller">

<div class="row">
    <div class="container">
        <div class="col-lg-8">
            <form role="form" method="post" >
                <div class="form-group" >
                    <input type="text" class="form-control" name="" ng-model="post.title" placeholder="Type the title here">
                </div>

                <div action="" class="form-group" ng-controller="TinyMceController">
                    <textarea ui-tinymce="tinymceOptions" ng-model="tinymceModel" style="height:300px">

                    </textarea>
                </div>

                <div class="form-group">
                    <input type="text" class="form-control" id="" ng-model="post.tags" placeholder="Atleast one related tag">
                </div>

                <button type="submit" class="btn btn-primary" ng-click="postsave()">Submit</button>
                <button class="btn btn-default">Discard</button>
            </form>
        </div>
        <div class="col-lg-4">
            RULES:
        </div>
    </div>
</div>

my controller:

app.controller('controller',['$scope','$rootScope','$http',function($scope,$rootScope,$http){

$scope.post={
    title:"",   
};


$scope.postsave= function(){
    $http({
        method:"POST",

        url:'http://localhost/../../...',
        data:        //I can pass title by using $scope.title but i aslo
                     //want to pass $scope.tinymcemodel


    })
    .success(function(result){
        alert(result);
    })
}

Any help would be great.Also suggest me if there is a better way of doing it.

Thank you.

0

1 Answer 1

1

Just like your post.tags is structured, you should do the same. Put all your children under a parent and submit the parent. Let's look at that:

$scope.formData = {}; //parent

Then your textarea/title should be altered accordingly:

ng-model="formData.title" //child
ng-model="formData.tinymcemodel" //child 

And then when you pass your data over, you can just pass this.formData.

$scope.postsave= function(){
    $http({
        method:"POST",
        url:'http://localhost/../../...',
        data: this.formData
    })
    .success(function(result){
        alert(result);
    })
};

This will properly send over the object to the server, which will have the key:value pairs as your title and tinymcemodel. Note that post.tags won't be included in this submission given that it belongs to another parent.

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

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.