2015-06-20 63 views

回答

1

嘗試在控制器中使用此指令。

app.directive('fileModel', ['$parse', function ($parse) { 
    return { 
     restrict: 'A', 
     link: function (scope, element, attrs) { 
      var model = $parse(attrs.fileModel); 
      var modelSetter = model.assign; 

      element.bind('change', function() { 
       scope.$apply(function() { 
        modelSetter(scope, element[0].files[0]); 
       }); 
      }); 
     } 
    }; 
}]); 

的Html

<input type="file" name="file" class="file-input-wrapper btn btn-default btn-primary" file-model="uploadFile" id="control" /> 

,同時要回你的控制器: 上傳的文件將在該$scope.uploadFile

相關問題