angular-base64-upload icon indicating copy to clipboard operation
angular-base64-upload copied to clipboard

Model not updating in controller

Open dracostheblack opened this issue 8 years ago • 11 comments

I have an issue where in my view i have

<input type="file" ng-model="attachment" class="ion-paperclip text-right float-right attachment" base-sixty-four-input onerror="errorHandler" onchange="fileChanged"/>

For one I have fileChanged defined in the controller and everytime I add a file that function comes up as undefined.

For two I have a div with {{attachment}} this is showing up correctly for when I add the file, but when I go to use that file in another function $scope.attachment, it's coming up as undefined.

Any help would be appreciated.

Sean

dracostheblack avatar Sep 01 '15 15:09 dracostheblack

It's on-change="fileChanged"

adonespitogo avatar Sep 01 '15 15:09 adonespitogo

I fixed that but $scope.attachment is still undefined after I do a file upload

dracostheblack avatar Sep 01 '15 15:09 dracostheblack

Can you post your code and angular version?

adonespitogo avatar Sep 01 '15 15:09 adonespitogo

Angular is 1.3.6

In my controller all I have is.

$scope.attachment={};

$scope.sendMessage = function () {
    console.log($scope.attachment.filename);
};

<div class="col col-10 text-right">
    <input type="file" ng-model="attachment" class="ion-paperclip text-right float-right attachment" base-sixty-four-input onerror="errorHandler" on-change="fileChanged"/>
</div>           

dracostheblack avatar Sep 01 '15 15:09 dracostheblack

Take a look at this plunkr code and see what's missing in your code.

adonespitogo avatar Sep 01 '15 15:09 adonespitogo

The only thing different I see is that i'm loading my controller from my module with stateprovider.

    $stateProvider
        .state('inbox.landing', {
            url: '/landing',
            views: {
                'bodyContent': {
                    templateUrl: 'js/modules/inbox/inbox.html',
                    controller: 'InboxCtrl'
                }
            }

dracostheblack avatar Sep 01 '15 15:09 dracostheblack

Are you triggering sendMessage() within fileChanged()?

adonespitogo avatar Sep 01 '15 15:09 adonespitogo

No, i was just seeing what the value of the attachment, I don't need to use fileChanged if it will update the scope variable.

dracostheblack avatar Sep 01 '15 16:09 dracostheblack

Also validation is not firing for me either.

dracostheblack avatar Sep 01 '15 17:09 dracostheblack

Hi @dracostheblack , @adonespitogo Please how did you solde this issue of model not updating in controller? I am using Angular 1.5.7 I get undefined on debugging.

lemetice avatar Jul 08 '16 17:07 lemetice

What is the solution?

sulmanweb avatar Nov 09 '16 09:11 sulmanweb