asafdav / ng-s3upload

Upload to S3 using AngularJS
MIT License
190 stars 83 forks source link

ngModel not being set after upload #32

Open jayrmotta opened 10 years ago

jayrmotta commented 10 years ago

Hi,

I've trying to use this directive for a while and now I'm stuck trying to set the remote url to a variable in my controller.

<div s3-upload bucket="'my-videos'" ng-model="video.url" s3-upload-options="{getOptionsUri: '/ws/config'}"></div>

After the upload a url appears by on a link called "Stored file" pointing to the correct URL but the ngModel is not set on my controller.

I've debugged the directive and suspected about the ngModel being passed to the post link funciotn of the directive, it doesn't seem to be the one I've set on the div above.

Would you guys be able to help me figure out how to get the generated url?

Thanks in advance.

btoone commented 10 years ago

What does your controller look like? I had the same issue but forgot I was using the controllerAs syntax so I just had to prefix the model.

Sorry I misread the first part of your question. I'm also wondering the best way to set the key (remote url) to a variable in the controller. Currently I have this working using a $watch but using a $watch in the controller isn't really the best idea. See my code below.

FYI I've asked in issue #36 if there is a better way. I think it would be ideal to have the events include the value so we could simply add a listener in the controller.

  $scope.$watch('vm.url', function(nv, ov) {
    console.debug(nv)
  });
davidstanley01 commented 9 years ago

On success, the service will emit a "s3upload:success" event. Just listen for that like so:

$scope.$on('s3upload:success', function(event, response, url) {
    console.log(url);
});
asafdav commented 9 years ago

ng-model should be updated, I tried to reproduce it but couldn't.

The event should be used in order to avoid watching the value and get notified after the upload was completed.

Has any of you experienced the same issue ?