ng-model and calculation displayed to a textbox.

1,527 views
Skip to first unread message

Deeksha Sharma

unread,
Feb 18, 2014, 9:37:07 AM2/18/14
to ang...@googlegroups.com
Hi everyone,

I need to have three textbox and I want to multiply two textboxes value and want to display the result in third textbox . and after this process the values of all three textboxes to sent to web api.

Can I do this If yes then suggest me how to do this.

i know Its stupid question but I am newbie to angularjs.

Thanks in advance.

Justin Walsh

unread,
Feb 18, 2014, 9:53:06 AM2/18/14
to ang...@googlegroups.com
Yes, you can do this.  Why don't you set up a plnkr, give it a try and shout if you get stuck.  For all you know, it may turn out to be simpler than you think.

Sander Elias

unread,
Feb 18, 2014, 9:56:56 AM2/18/14
to ang...@googlegroups.com
Gi Deeksha,


Regards
Sander

Deeksha Sharma

unread,
Feb 18, 2014, 10:17:01 AM2/18/14
to ang...@googlegroups.com
Thanks Dear , I have one more problem .Can I ask it.


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/1mnra0vamtg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Sander Elias

unread,
Feb 18, 2014, 10:37:34 AM2/18/14
to ang...@googlegroups.com
Hi Deeksha,

Sure, questions are for free ;)

Regards
Sander

Deeksha Sharma

unread,
Feb 19, 2014, 12:02:04 AM2/19/14
to ang...@googlegroups.com
Actually,I want to send an array of json object  to .net web api.and I am doing like this.

It is my .net web api controller.
  public void Post(NewCustomer customer)
        {
           
        }


where NewCustomer  is a class

public class NewCustomer
    {
        public IList<Customer> Customers { get; set; }
    }


and Customer class is like
  public class Customer
    {

        public int CustomerId { get; set; }
        public string CustomerName { get; set; }
        public int Age { get; set; }
    } 


and at client side I am using Angularjs,my controller is

app.controller('CustomerListController', function ($scope, customerService) {
    $scope.CustomerList = [{ "CustomerId": 1, "CustomerName": "deeksha", "Age": 23 }, { "CustomerId": 2, "CustomerName": "pooja", "Age": 34 }];

    $scope.Add = function () {
        alert(JSON.stringify($scope.CustomerList));
        customerService.addCustomer(JSON.stringify($scope.CustomerList));
    };
});


and Service is like


var customerAPI = '/api/customer/:Id';
app.factory("Customer", function ($resource) {
    return $resource(
        customerAPI,
        { Id: "@Id" },
        {
            "update": { method: "PUT", isArray: true }
        }
    );
});

app.service("customerService", function ($resource, Customer) {   
    this.addCustomer = function (customerDetail) {     
        Customer.save(customerDetail);   
    };   
    });



I am not getting where is problem because value is being sent by client side and I can see it in firebug but server side web api controller is showing null value.I want solution of it 
Thanks in advance to you .
  

Jim Lavin

unread,
Feb 19, 2014, 5:51:36 PM2/19/14
to ang...@googlegroups.com
Looks like your problem is the fact that you have a method Post on your WebApi controller but you are doing a Put in your service.

You can either change the name of the WebApi Put or change the method in your resource call to Post.

Hope this gets you further along.

Deeksha Sharma

unread,
Feb 21, 2014, 7:21:43 AM2/21/14
to ang...@googlegroups.com
Thanks .


Resolved it by putting

{
"save":{method:"POST",isArray:true}

Tarek Faham

unread,
Oct 19, 2016, 11:41:47 AM10/19/16
to Angular
Hi All,

I have updated the pnlkr.co code sample to use calculation functions from `ng-value` instead of `watch()`. Also, I provided a sample to show how to format the output. For example, to show empty string if result is zero.

Using ng-value will save you the effort of finding out which input variables need to be included in the watch()` function call.

See link below:

http://plnkr.co/edit/Fmqw0wp37Ndk1yuWvFkV?p=preview
Reply all
Reply to author
Forward
0 new messages