For the code, i have take inspiration from this :
https://codepen.io/alexandergaziev/pen/JdVQQm
So, for the HTML, i have do this :
<div class="file_input_div">
<div class="file_input">
<label class="image_input_button mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-js-ripple-effect mdl-button--colored">
<i class="material-icons">file_upload</i>
<input id="file_input_file" class="none" type="file"
ng-model="file1"
onchange="angular.element(this).scope().changeInputText(this);
angular.element(this).scope().changeState();"/>
</label>
</div>
<div id="file_input_text_div" class="mdl-textfield mdl-js-textfield textfield-demo"
ng-model="filetextdiv">
<input class="file_input_text mdl-textfield__input"
type="text" disabled readonly id="file_input_text"
ng-model="filetext" />
<label class="mdl-textfield__label" for="file_input_text">
</label>
</div>
</div>
And in the corresponding controller :
$scope.changeInputText = function(){
console.log($scope.file1);
console.log($scope.filetext);
console.log($scope.filetextdiv);
var str = $scope.file1.value;
var i;
if (str.lastIndexOf('\\'))
{
i = str.lastIndexOf('\\') + 1;
}
else if (str.lastIndexOf('/'))
{
i = str.lastIndexOf('/') + 1;
}
$scope.filetext.value = str.slice(i, str.length);
};
$scope.changeState = function() {
console.log("Coucou");
if ($scope.filetext.value.length != 0)
{
if (!$scope.filetextdiv.classList.contains("is-focused"))
{
$scope.filetextdiv.classList.add('is-focused');
}
}
else
{
if ($scope.filetextdiv.classList.contains("is-focused"))
{
$scope.filetextdiv.classList.remove('is-focused');
}
}
}
But there is a problem, and i don't undestand why :
When I chose a file, the functions in the controller are called.
But, the value (designed by ng-model, file1, filetext and filetextdiv) are undefined.
Why ?