我试图在我的代码中实现这个指令而没有多少succces.
angular-material-fileinput.
我按照github页面中的说明添加“lfNgMdFileInput”到我的模块依赖项中,在HTML中添加了html标记,除了一件事之外,一切都很好.
根据文档,我通过使用$scope.’watch(‘lfFilesName’,function(old,new){…})来捕获字段中输入的数据的方式.
指令处理的数据很好,并且在指令$scope中保存所有内容都没有问题,但$watch事件永远不会被触发,除非它被初始化.
// 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>
Partials / 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',oldVal){ console.log($scope.files02); },true); $scope.$watch('files01',oldVal){ console.log($scope.files02); }); //unrelated stuff }