2
我試圖在我的angularjs組件中檢索表單名稱,同時表單正在加載,因爲我想根據解析的某些數據驗證將表單狀態設置爲dirty到組件。我能夠訪問表單名稱,一旦表單完全加載說在一個提交內,但我無法做到這一點上的負載,我怎麼能做到這一點。我正在使用ui.router,因此控制器名稱將根據狀態進行設置。
<form class="form-horizontal" name="detail.myForm">
<button ng-click="detail.submit">
</form>
app.component('myDetail', {
bindings: {
alldetails: '<'
},
templateUrl: '/app/detail.html',
controllerAs: 'detail',
controller: function ($state, $transitions, $scope) {
var detail=this;
/*validateData in the alldetails here */
$scope.detail.myForm.$setDirty(); // issue here saying undefined
detail.submit =() =>{
$scope.detail.myForm.$setPristine() //works without any issue
}
}
嗨萊昂納多,我無法去小提琴。應用程序正在拋出異常,表示無法找到需求「表單」。我相信窗體是我的例子detail.warehouseForm上面的名稱。 –
嘿,小提琴工作正常(http://fiddle.jshell.net/rybkwf25/)。在我提供的示例中,您不需要將'ngFormController'指定給您的模型,因爲您可以「需要」它。 –