-
Notifications
You must be signed in to change notification settings - Fork 1.1k
TypeError: "Uploader" must be an instance of FileUploader when using ControllerAs #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
i don't know really if the problem comes with the controllerAs property, but in my case i was getting this error because uploader was undefined at the time of creating the template. so my solution was to include an ng-if="uploader" to the divs where the uploader was involved. for instance ` |
I am using controllerAs: 'vm' and i dont't have any problems at all. Controller: angular
.module('app.dashboard')
.controller('DashboardController', DashboardController);
DashboardController.$inject = ['FileUploader'];
/* @ngInject */
function DashboardController(FileUploader) {
var vm = this;
var uploader = new FileUploader();
vm.uploader = uploader;
} You can even bind the uploader directly without problems: var vm = this;
vm.uploader = new FileUploader(); You have to make sure that all references to the uploader in the html are 'documentVm.uploader' |
Thanks @josencv Setting all references in html to be documentVm.uploader resolved the issue |
Please could you confirm what "setting all references" means? There's only one reference in the HTML and it's in my input field: <input class="form-control ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" ng-model="model[options.key]" id="formly_1_upload_photo_8" name="formly_1_upload_photo_8" formly-custom-validation="" required="true" type="file" nv-file-select="userVm.fileUploader"> However... it must be noted, this input field is created by Formly... I'm not sure who the cuplrit is. |
I need more information Are you using "controllerAs: 'userVm'"? |
//use ng-if to make sure that vm.uploader already initialized vm.uploader = new FileUploader( ... // HTML will not render until FileUploader okay |
I began switching to using controllerAs, and now I am getting the TypeError: "Uploader" must be an instance of FileUploader.
The following worked:
Controller: $scope.uploader = new fileUploader({ url: "Document/uploadFile" });
Html: uploader="uploader"
But with controllerAs, these have changed to:
Controller: documentVm.uploader = new fileUploader({ url: "Document/uploadFile" });
Html: uploader="documentVm.uploader" or uploader="uploader"
The text was updated successfully, but these errors were encountered: