Skip to content
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

Model not updating in controller #51

Open
dracostheblack opened this issue Sep 1, 2015 · 11 comments
Open

Model not updating in controller #51

dracostheblack opened this issue Sep 1, 2015 · 11 comments

Comments

@dracostheblack
Copy link

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

@adonespitogo
Copy link
Owner

It's on-change="fileChanged"

@dracostheblack
Copy link
Author

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

@adonespitogo
Copy link
Owner

Can you post your code and angular version?

@dracostheblack
Copy link
Author

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>           

@adonespitogo
Copy link
Owner

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

@dracostheblack
Copy link
Author

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'
                }
            }

@adonespitogo
Copy link
Owner

Are you triggering sendMessage() within fileChanged()?

@dracostheblack
Copy link
Author

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
Copy link
Author

Also validation is not firing for me either.

@lemetice
Copy link

lemetice commented Jul 8, 2016

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.

@sulmanweb
Copy link

What is the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants