简体   繁体   English

AngularJS数字输入和默认值

[英]AngularJS number input and default value

I have a weird issue with AngularJS and the number input. 我对AngularJS和数字输入有一个奇怪的问题。 The default value will be populated for a second and then the default number disappears. 默认值将填充一秒,然后默认数字将消失。 Tried on FX and Chrome. 试过FX和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. 我在数字输入上也有一个ng-init="product.quantity=1" ,然后数字1闪烁然后消失。

<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. 谢谢。

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. 您的分配quantity中的number输入,但服务器发送quantitystring ,如果u cast的数据类型来int从服务器,或更改number输入到一个text它会工作。

so if you go with int then the data should be like, 所以,如果你使用int那么数据应该是这样的,

{
    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"
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM