2016-12-02 24 views
0

我今天變量在我的控制變量作爲如何使用變量從控制器內的HTML

let today= new Date().toISOString().split('T')[0]; 

給當前的日期,我想是HTML格式的最小日期屬性設置。

下面

是我的HTML

<input class="form-control" type="datetime" date-time auto-close="true" view="date" 
min-date=    min-view="date" maxlength="10" format="dd/MM/yyyy" 
ng-model="$ctrl.DateInput" placeholder="date" required="true" > 

我們如何通過從控制器變量值html..If我設置爲min-日期=「2016年12月2日」這是working..Now我想從今天的變量中獲得這個價值......我們如何做到這一點。 謝謝。

+0

在'sc中帶上'variable'打開並顯示在視圖中使用'ng-model' – Sravan

回答

2

您需要將值分配給$scope對象在控制器

$scope.today = new Date().toISOString().split('T')[0]; 

或者,如果你使用controller as syntax,將其分配到this控制器

this.today = new Date().toISOString().split('T')[0]; 

而在html使用

min-date="{{ today }}" with $scope 
min-date="{{ $ctrl.today}}" with controller 
+0

它給了我參考錯誤 angular_angular.js?hash = 744f2a2 ...:12545 ReferenceError:今天沒有定義 –

+0

@HVarma你注入了'$ scope'嗎?創建一個小提琴幫助我們來幫助你) –

+0

它的工作,我試過this.today>它力量working..But $ scope.today工作......謝謝 –

相關問題