MD Gosoddin MD Gosoddin - 12 days ago 8
AngularJS Question

How to used directive in angular

i copied some code from a project i understand complete project but i cofused wat is ".directive" if i chane any thing here the file is not uploding please helpme

Html code

<input type="file" name="attachment" data-ak-file-model="tutorial.attachment" />


Angular.Js
Here if i change a single word in "akFileModel" during the run time file not uploding pleasse explain this portion i copied this from https://www.codeproject.com/tips/878730/file-upload-using-angularjs-and-asp-net-mvc

.directive("akFileModel", ["$parse",
function ($parse) {
return {
restrict: "A",
link: function (scope, element, attrs) {
var model = $parse(attrs.akFileModel);
var modelSetter = model.assign;
element.bind("change", function () {
scope.$apply(function () {
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);

Answer

Read on how to name directive and use it in the HTML

.directive("akFileModelsam", ["$parse",

sample:

 <input type="file" name="attachment" class="form-control" data-ak-file-modelsam="tutorial.attachment" />