Custom directive with attribute

Description

The following code shows how to create Custom directive with attribute.

Example


<!--   w  ww .j  ava2s .com-->
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
var app = angular.module('myApp', []);
app.directive('yourInput', function() {
    return {
        restrict: 'E',
        scope: {
            form: '='
        },
        template: '<span>Hello World</span>',
        link: function(scope, element, attrs) {
            console.log(scope.form);
        }
    };
});
</script>
</head>
<body>
  <p><em>Check the console</em></p>
<div ng-app="myApp">
    <div ng-form="myForm">
        <your-input form="myForm"></your-input>
    </div>
</div>

</body>


</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities