AngularJS: how to implement a simple file upload with multipart form?

A real working solution with no other dependencies than angularjs (tested with v.1.0.6) html Angularjs (1.0.6) not support ng-model on “input-file” tags so you have to do it in a “native-way” that pass the all (eventually) selected files from the user. controller The cool part is the undefined content-type and the transformRequest: angular.identity that give at the $http the ability to … Read more

What does ngInject do in the following piece of code?

‘ngInject’; does nothing by itself, it’s just a string literal. A tool called ng-annotate uses it as a flag : if a function starts with ‘ngInject’;, it will be processed by ng-annotate. Basically, ng-annotate will transform to in order to make the code minification-safe. If you’re not using ng-annotate, you can safely ignore or remove the expression. Be … Read more

Why do we use $rootScope.$broadcast in AngularJS?

$rootScope basically functions as an event listener and dispatcher. To answer the question of how it is used, it used in conjunction with rootScope.$on; However, it is a bad practice to use $rootScope as your own app’s general event service, since you will quickly end up in a situation where every app depends on $rootScope, and you do not … Read more

In AngularJS, what’s the difference between ng-pristine and ng-dirty?

The ng-dirty class tells you that the form has been modified by the user, whereas the ng-pristine class tells you that the form has not been modified by the user. So ng-dirty and ng-pristine are two sides of the same story. The classes are set on any field, while the form has two properties, $dirty and $pristine. You can use the $scope.form.$setPristine() function to reset a form to … Read more

getting the ng-object selected with ng-change

Instead of setting the ng-model to item.size.code, how about setting it to size: Then in your update() method, $scope.item will be set to the currently selected item. And whatever code needed item.size.code, can get that property via $scope.item.code. Fiddle. Update based on more info in comments: Use some other $scope property for your select ng-model then: Controller: