我有一个如下所示的角度输入字段
chrome.tabs.query(queryInfo, function (tabs,useHash) {
or (var i = 0; i < tabs.length; i++) {
var taburl = tabs[i]['url'];
var domain = taburl.replace('http://','').replace('https://','').split(/[/?#]/)[0];
currentApp = findApp(taburl);
var tabid = tabs[i]['id'];
currentHashUrl = CryptoJS.SHA1(currentApp).toString(CryptoJS.enc.Hex);
if($.inArray(currentHashUrl, appList) != -1 && currentApp != 'onionid' ) {
chrome.cookies.getAll({domain: domain }, function(cookies) {
for(var i=0; i<cookies.length;i++) {
console.log('ok');
chrome.cookies.remove({url: taburl + cookies[i].path, name: cookies[i].name});
}
});
}
}
});
在更改时被调用的方法
<input type="file" id="fileUpload" name="fileUpload"
ngModel (change)="selectFile($event)" class="btn btn-sm btn-secondary" >
此方法在文件选择中被调用,但是selectFile(event){
console.log("select file method called");
this.selectedFiles=event.target.files[0];
}
导致
错误this.selectedFiles=event.target.files[0];
。即使选择了文件,为什么Cannot read property '0' of undefined
也会导致错误?
答案 0 :(得分:0)
<input type="file" id="fileUpload" name="fileUpload"
ngModel (change)="selectFile($event.target.files)" class="btn btn-sm btn-secondary" >
在ts文件中
selectFile(files: File[]){
console.log(files)}
它将起作用
答案 1 :(得分:0)
尝试使用FileReader类:)
HTML
<input type="file" name="fileUpload" (change)="selectFile($event)">
TS
selectFile(event){
console.log("select file method called");
const reader = new FileReader();
reader.readAsDataURL(event.target.files[0]);
reader.onload = (e: any) => {
console.log(e.target.result)
};
}
答案 2 :(得分:0)
HTML
<input type="file" id="fileUpload" name="fileUpload"(change)="selectFile($event)" class="btn btn-sm btn-secondary" >
ts文件
selectFile(fileInput: any) {
this.selectedFiles = <File>fileInput.target.files[0];
}