0
我有一個自定義指令,用於檢測類型文件的輸入何時發生更改。發生這種情況時,我想查找另一個輸入並更改其ng-model
。我似乎無法讓模型更改被觸發。我做了研究,找不到答案。這是我引用here當從文件選擇指令更改值時更新ng-model
//my controller
$scope.headShotUpload = function (event) {
var path = '',
id = event.target.id.toString(),
files = event.target.files,
tempString = '';
if(id.includes('nfl')){
path = $scope.filePaths.headShot.nfl +'/'+ files[0].name;
tempString = id.replace("nfl-","");
var labelInputId = tempString+'-path'
var input = $(labelInputId);
input.val(path);
input.trigger('input');
}
};
//my directive
angular.module('app')
.directive('customOnChange', function() {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var onChangeHandler = scope.$eval(attrs.customOnChange);
element.bind('change', onChangeHandler);
}
};
});
<td class="rcs-table-btn">
<span >
<label class="btn btn-default btn-file btn-rcsorange" >NFL<input type="file" style="display: none;" id="offense-top-header1-headshot-nfl-1" custom-on-change="headShotUpload"></label>
</span>
<span>
<label class="btn btn-default btn-file btn-rcsorange" >NCAA <input type="file" style="display: none;" id="offense-top-header1-headshot-ncaa-1" custom-on-change="headShotUpload"></label>
</span>
</td>
<td class="rcs-table-input">
<input type="text" class="rcs-input-table" id="offense-top-header1-headshot-1-path" placeholder="(path)" ng-model="page.offense.list[player.position].header1[0].headShot">
</td>
你好,如果任何人碰到這個問題我來解決它通過更換通過document.getElementById()的jQuery($)和它的工作。出於某種原因,jquery不適合我。我不得不尋找原因。 – inhaler