angularjs - How to have access to directive scope value from my main controller -
web api file upload angularjs - https://code.msdn.microsoft.com/angularjs-with-web-api-22f62a6e#content
this tutorial upload selected files server there no way selected filename exception directive,
please, need way filename of selected file directive scope, can use in controller
this focus area
(function () { 'use strict'; angular .module('app.photo') .directive('egphotouploader', egphotouploader); egphotouploader.$inject = ['appinfo','photomanager']; function egphotouploader(appinfo, photomanager) { var directive = { link: link, restrict: 'e', templateurl: 'app/photo/egphotouploader.html', scope: true }; return directive; function link(scope, element, attrs) { scope.hasfiles = false; scope.photos = []; scope.upload = photomanager.upload; scope.appstatus = appinfo.status; scope.photomanagerstatus = photomanager.status; } } })();
the directive template
<form name="newphotosform" role="form" enctype="multipart/form-data" ng-disabled="appstatus.busy || photomanagerstatus.uploading"> <div class="form-group" ng-hide="hasfiles"> <label for="newphotos">select , upload new photos</label> <input type="file" id="newphotos" class="uploadfile" accept="image/*" eg-files="photos" has-files="hasfiles" multiple> </div> <div class="form-group" ng-show="hasfiles && !photomanagerstatus.uploading"> <div> file name:{{photos[0].name}} </div> <input class="btn btn-primary" type="button" eg-upload="upload(photos)" value="upload"> <input class="btn btn-warning" type="reset" value="cancel" /> </div>
from main controller, want have access directive scope {{vm.photos[0].name}}
function link(scope, element, attrs) { scope.hasfiles = false; scope.photos = []; scope.upload = photomanager.upload; scope.appstatus = appinfo.status; scope.photomanagerstatus = photomanager.status; } // scope need in main controller, please how can out. scope.photos = [];
Comments
Post a Comment