Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to grab the custom directive of Angular in deep.

With some online post, I got a basic understanding on the syntax. Have heard a lot on datepicker directive.

So can someone please post an example of datepicker angular directive step by step?

Please ans this queries along with it:-

1)What is the use of require attribute?

2)When should I use 'A','E' for restrict option?(For ex datepicker)

3)What is the difference between compile & link function?

What I have tried:

app.directive('datetimepicker', function () {
return {
    restrict : 'AE',
    require :'ngModel',
    link : function(scope,ele, attr){}
    });
Posted
Updated 18-Feb-17 6:32am

Quote:
1)What is the use of require attribute?

The require attribute will try to access another directive called (in your case) ngModel.

Quote:
2)When should I use 'A','E' for restrict option?(For ex datepicker)

This restricts the use of a your directive to a specific method of using it.

A = attribute. So something like <span datetimepicker=""></span>
E = Element. So something like <datetimepicker>
C = Class. So something like <span class="datetimepicker"></span>
M = Comment. So it would be something like <!--directive:datetimepicker-->

I don't think you can use both AE for creating a directing but Im not 100% on that.

Quote:
3)What is the difference between compile & link function?


For this I would direct you to this link for an explanation: javascript - What is the difference between compile and link function in angularjs - Stack Overflow[^]

Then as for your request for someone to provide you step by step instructions for creating a date picker directive, I'd direct you to use google. This is beyond the scope of Quick Answers and isn't meant to provide tutorials.

Here are some promising links:

angularjs-datepicker[^]

javascript - AngularJS custom datepicker directive - Stack Overflow[^]

GitHub - g00fy-/angular-datepicker: calendar and datepicker directives for angular[^]

[Material Angular Js - DatePicker]

I'd also recommend you take a look at the Directive documentation for angular:

[Angular JS Directive]
 
Share this answer
 
v2
Comments
Member 12906141 6-Jan-17 4:14am    
Thanks David. But can you please complete your ans as it seems left half. [A = attribute. So something like ???]
David_Wimbley 6-Jan-17 11:12am    
I've fixed the html encoding, forgot about that.
You could simply consider using `ui-bootstrap` plugin `datepicker` component. It has simple syntax uib-datepicker. UI-bootstrap also has converted almost all bootstrap component to angularized version of it.

<div uib-datepicker ng-model="dt"></div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900