i wish to insert a record in mysql table using angularjs. Table: Product product_id, name, description.

i wish to have two text fields and a save button and on the click of save button record should be inserted in mysql table. i referred to the following link :

but all in vain...

index.html

    <html ng-app>
    <head>
        <script src="../angular-1.0.1.min.js"></script>
        <script src="js/controllers.js"></script>
    </head>
    <body>
    <ul ng:controller="ProductListCtrl">
        <li ng:repeat="product in products">
            {{product.name}}
        </li>
    </ul>
    <form method = 'post'>
        Name : <input type = 'text' name = 'txtName'/>
        Description : <input type = 'text' name = 'txtDescription'/>
        <button ng:click="saveProduct()">New Product</button>
        <div id="content">
            <ng:view></ng:view>
        </div>
    </form>
    </body>
</html>

where do i write saveProduct() method and what should i write in it?

what should i do to add a record in mysql from angularjs?

share|improve this question

1 Answer

AngularJS is a client side MV* framework. Most Client side frameworks expect that the decision with regard to the DOM manipulation be left to them and they be just fed the data from the server side.

This data will ofcourse in your case be stored in MySQL which you will have to retrieve through PHP and write a simple RESTful interface to your DB. In your angular code, say your PHP restful endpoint would be something like

http://mywebsite.com/api/product

If you do a simple POST call through ng-resource it is equivalent to making a save on your DB. For details on how to set this up, you could have a look at some of the ng-resource examples floating around.

share|improve this answer
can you explain in detail, i mean with some sample code? – z22 Aug 23 '12 at 10:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.