私はこの命令を自分のコードに実装することを大いに尽くしています。 angular-material-fileinput。
私はgithubページの指示に従い、 "lfNgMdFileInput"をモジュールの依存関係に追加し、HTMLタグをHTMLに追加しました。
ドキュメントに従ってフィールドに入力されたデータをキャッチする方法は、$scope.$watch('lfFilesName',function(old,new){...})
を使用しています。
ディレクティブ$ scopeで問題なくデータがすべて処理されますが、$ watchイベントは初期化されたときを除きトリガーされません。
追加する必要があるものがあれば教えてください。コードitsselfはこれです:
// the piece of html
<lf-ng-md-file-input lf-files="files02" lf-api="api02" multiple></lf-ng-md-file-input>
// the piece of js; PS: While the selected files appear on the directive scope, they don't appear in the scope of my controller,
// witch i guess is normal but it would still have to catch the watch event, right?
$scope.$watch('files02.length',function(newVal,oldVal){
console.log($scope.files02);
});
EDIT1:(コードスニペット)
<body ng-controller="HomeCtrl">
<div ui-view layout="row" ng-style="checkHeightReq()">
<md-tabs md-selected="selectedIndex" md-dynamic-height md-stretch-tabs="always" flex="100" md-border-bottom="">
<md-tab label="{{lang.uploadDocuments}}" ng-disabled="tabsDisabled.tab4">
<div ng-include="'partials/tabUploadDocuments.html'" ng-controller="UploadDocCtrl"></div>
</md-tab>
</md-tabs>
</div>
</body>
パーシャル/ tabUploadDocuments.html:
<lf-ng-md-file-input lf-files="files01"></lf-ng-md-file-input>
<lf-ng-md-file-input lf-files="files02"></lf-ng-md-file-input>
UploadDocCtrl:
angular.module('demo').controller('UploadDocCtrl', UploadDocuments);
UploadDocuments.$inject = ['$scope','LangVars','$mdMedia', '$mdToast'];
function UploadDocuments($scope, LangVars,$mdMedia, $mdToast) {
//unrelated stuff
$scope.$watch('files02',function(newVal,oldVal){
console.log($scope.files02);
},true);
$scope.$watch('files01',function(newVal,oldVal){
console.log($scope.files02);
});
//unrelated stuff
}
あなたは、「選択したファイルは、ディレクティブのスコープに表示されますが、彼らは私のコントローラの範囲には表示されません」とはどういう意味ですか?別の指令で 'lf-ng-md-file-input'を使用していますか? '$ watch'はデフォルトで' $ scope'のプロパティを監視します。それが別の指示にある場合は、それを渡す必要があります。もう少し文脈が役立つだろう。 – fodma1
いいえ、私は別の指令でlf-ng-md-file-inputを使用していません。私は、タグを含む単純なhtmlファイルを持っています、それは角度の材料タグ()の中にインポートされ、特定のタブは、$ウォッチイベントをキャッチしようとするところに独自のコントローラを持っています。それが役に立つと思うなら、私のコードがどのように構造化されているかのスニペットを投稿できます。 –
IvanSt
私はコードが役立つかもしれない場合、どのように構造化されているかについてのいくつかのコードスニペットで投稿を編集しました。 – IvanSt