2015-09-17 97 views
-1

HTML佔位符不與NG-模型工作

隨着NG-模型 - 不工作

<input type="text" ng-model="Event.Sponsor.Amount" name="donationAmount" placeholder="{{PlaceHolderOther}}" required /> 

沒有NG-模型 - 工作

<input type="text" name="donationAmount" placeholder="{{PlaceHolderOther}}" required /> 

JS

$scope.PlaceHolderOther = "$50.00"; 

你能告訴我爲什麼placeholder不與ng-model工作?沒有ng-model,工作正常。提前感謝。

出把(當它運行時)

<input type="text" name="donationAmount" placeholder="$50.00" ng-model="Event.Sponsor.Amount" required="" class="ng-pristine ng-valid ng-valid-required"> 

它顯示了placeholder值properly.But不會顯示給user.Why?

更新:我已經找到了問題。那是texbox已經自動初始化。當我們刪除該值,然後它顯示佔位符值。所以如何避免這種情況下默認?

+0

嘗試'$ scope.Event = {PlaceHolderOther: '$ 50.00'}'; – Vineet

回答

-1

嘗試data-ng-model,參考http://jsfiddle.net/pranav93/ww3k4hxp/6/。 喜歡的東西,

<input id="ship-address-line-3" name="ship_address_line3" placeholder="{{shippingFormOrderItemAction.ship_address_line3}}" data-ng-model="retryAutoDetails.ship_address_line3" type="text"> 
-1

你有沒有定義

$scope.Event = {}; 

與嘗試以上。

是:根據最新的答案。(糾正錯字錯)

+0

它應該是'$ scope.Event' – Vineet

+0

事情是,它與'type = number'一起工作正常,但不能處理'text'。這真的很奇怪。 – Sampath

+0

我沒有看到與文本和數字的關係,但認爲$ scope.Event = {};是問題。 –