Новичкам в угловой. Очень простой вопрос. У меня есть следующий код.AngularJS Передача значения от функции директивной ссылки к контроллеру
Я просто хочу показать количество файлов внизу. Я привязываю переменную fileCount к области видимости, но она не работает.
var app = angular.module('fileUploader', []);
app.controller('upload', function($scope){
\t $scope.fileCount = 0;
})
.directive("customDirective", function(){
\t return{
\t \t link: function(scope, el, attrs){
\t \t \t el.bind("change", function(event){
\t \t \t \t console.log(event.target.files.length);
\t \t \t \t scope.fileCount = event.target.files.length;
\t \t \t });
\t \t }
\t }
});
\t <head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
\t </head>
\t <body>
\t <div ng-app="fileUploader" ng-controller="upload">
\t \t <input custom-Directive type="file"/>
\t \t <p>The file count is: {{fileCount}}</p>
\t </div> \t \t
\t </body>
Спасибо за ваш ответ! – catlovespurple
@catlovespurple, no prob! Рад, что это сработало. –