3

I have a weird issue with AngularJS and the number input. The default value will be populated for a second and then the default number disappears. Tried on FX and Chrome.

The data returned from the server is:

{
    "name":"Rodolfo Heller",
    "desc":"Et ullam autem iure. Facere non fuga sit. Dolorum reprehenderit voluptatem vero rem at in.",
    "sell":"44.44",
    "image":"xxxx",
    "id":"1",
    "quantity":"1"
}

I also have an ng-init="product.quantity=1" on the number input, yet the number 1 flashes then disappears.

<input type='number' min="1" step="1" class='form-control' ng-model="product.quantity" ng-init="product.quantity=1">

Any ideas why the default value disappears?

Thanks.

5
  • There are no comma in your json. Is your real server return, or is an error in a post ? Commented Feb 1, 2015 at 16:23
  • Ah sorry it is a copy and paste from the Chrome dev tools. Fixed now. Commented Feb 1, 2015 at 16:26
  • If you add {{product.quantity}} in your template. It happens the same thing ? Commented Feb 1, 2015 at 16:29
  • No, the number is visible then. Commented Feb 1, 2015 at 16:30
  • Can you make a jsfiddle as everything seems fine. Tested it here link Commented Feb 1, 2015 at 16:31

1 Answer 1

4

may be the issue with your datatypes return from the server,

{
    desc: "Et ullam autem iure. Facere non fuga sit. Dolorum reprehenderit voluptatem vero rem at in."
    id: "1"
    image: "hidden"
    name: "Rodolfo Heller"
    quantity: "1"                   // String value for quantity
    sell: "44.44"
}

your assign quantity in to a number input, But the the server sends the quantity as a string, if u cast the datatype to int from the server, or change number input to a text it will work.

so if you go with int then the data should be like,

{
    desc: "Et ullam autem iure. Facere non fuga sit. Dolorum reprehenderit voluptatem vero rem at in."
    id: "1"
    image: "hidden"
    name: "Rodolfo Heller"
    quantity: 1                   // int
    sell: "44.44"
} 
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.