Reputation: 31
<input type="file" accept="image/*" ng-model="imageupload" />
My problem is, I want to call a function when the user will browse an image file then a function will trigger.
The value of the ng-model of the input type file is going to change. Then a function will call, that function will upload the image to a folder.
That has to implement in AngularJS
Upvotes: 1
Views: 2024
Reputation: 1365
Consider u have a html element with type as file,now add an ng-change directive to that element.
<input type="file" ng-change="trigger()">
Now in your js refer the code as below
var app=angular.module('app',[]);
app.controller('MyCtrl',function($scope){
$scope.trigger=function(){
//your code to copy a file to folder
}
});
Upvotes: 1
Reputation: 965
You should look at ng-change
directive of input field
Evaluate the given expression when the user changes the input.
Example
HTML:
<body ng-controller="mainCtrl">
<input ng-model='imageUri' type='text' ng-change='alert()'/>
</body>
Angular code:
app.controller('mainCtrl', function($scope){
$scope.alert = function(){
alert('hello');
}
});
Upvotes: 2