AngularJS Custom Directive

I am not going to write another blog to explain about the custom directives in Angular JS. The documentation of AngularJS is a perfect source for learning about them.In this post, lets just play around a custom directive.

I just want to display the name of a file browsed. So, here goes the simple controller and custom directive code,


var coreApp = angular.module("coreApp", []);

coreApp.directive('fileUpload', function()
	return {
	scope : false,
	link : function(scope, elem, attr)
		elem.on('change', function(event)
			var file =[0];
			{ =;;


coreApp.controller('myController', function($scope)
	$ = {
		name : '',


And here is the simple html page,


		<title>Angular JS Directive.</title>
		<script src="js/angular.min.js"></script>
		<script src="js/main.js"></script>
	<body ng-app="coreApp" ng-controller="myController">
		<h2>AngularJS Sample Application</h2>
			<input type="file" file-upload />
			<p>File Selected </p>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s