22
33var app = angular . module ( 'MyApp' , [ 'ngRoute' ] )
44
5- app . config ( function ( $routeProvider )
6- {
7- $routeProvider
8- . when ( '/' ,
9- {
10- templateUrl : "partials/sample.html" ,
11- controller : "MainPageCtrl"
12- } )
13- . when ( '/pageTwo' ,
14- {
15- template : '<div>This is page <strong>two</strong>!</div>'
16- } )
17- . when ( '/calendar/:month/:day/:year' ,
18- {
19- templateUrl : "partials/calendar.html" ,
20- controller : "CalendarCtrl"
21- } )
22- . otherwise (
23- {
24- template : '<div><strong>THERE IS NO PAGE HERE!</strong></div>'
25- } )
26- } )
27-
28- . controller ( "CalendarCtrl" , function ( $scope , $routeParams )
29- {
30- $scope . model = {
31- message : "Date: " + $routeParams . month + " / "
32- + $routeParams . day + " / "
33- + $routeParams . year
34- }
35- } )
36-
37- . controller ( 'MainController' , function ( $scope )
38- {
39- $scope . labelName = "New Button" ;
40- $scope . newElement = angular . element ( '<div class="btn btn-default">' +
41- $scope . labelName + '</div>' ) ;
42- } )
43-
44- . directive ( 'compileDirective' , function ( $compile )
45- {
46- return {
47- restrict : 'E' ,
48- template : '<div>New compile template</div>' ,
49- controller : 'MainController' ,
50- link : function ( scope , elm , attrs )
51- {
52- var compileIt = $compile ( scope . newElement ) ;
53- var content = compileIt ( scope ) ;
54- elm . append ( content ) ;
55- }
56- }
57- } )
58-
59- . directive ( 'pageDirective' , function ( )
60- {
61- return {
62- restrict : 'E' ,
63- template : '<div>Here is a new button</div>' ,
64- controller : 'MainController' ,
65- scope : '=' ,
66- compile : function ( tElem , tAttrs )
67- {
68- console . log ( 'compile it. This is the original compiled DOM.' ) ;
69- return {
70- pre : function preLink ( scope , iElement , iAttrs )
71- {
72- console . log ( 'pre' ) ;
73- iElement . html ( '<div class="panel panel-default">Now a panel</div>' ) ;
74- } ,
75- post : function postLink ( scope , iElement , iAttrs )
76- {
77- console . log ( 'post' ) ;
78- iElement . append ( scope . newElement ) ;
79- }
80- }
81- }
82- }
83- } )
84-
85- . directive ( 'pageDirectiveTwo' , function ( )
5+ app . provider ( "box" , function ( )
866{
7+ var hex ;
878 return {
88- restrict : 'E' ,
89- template : '<div>Here is a second button</div>' ,
90- controller : 'MainController' ,
91- scope : '=' ,
92- compile : function ( tElem , tAttrs )
9+ setColor : function ( value )
9310 {
94- console . log ( '2 compile it. This is the original compiled DOM.' ) ;
95- return {
96- pre : function preLink ( scope , iElement , iAttrs )
97- {
98- console . log ( '2 pre' ) ;
99- } ,
100- post : function postLink ( scope , iElement , iAttrs )
101- {
102- console . log ( '2 post' ) ;
103- iElement . append ( scope . newElement ) ;
104- }
105- }
106- }
107- }
108- } )
109-
110- . directive ( 'pageDirectiveThree' , function ( )
111- {
112- return {
113- restrict : 'E' ,
114- template : '<div>Here is a third button</div>' ,
115- controller : 'MainController' ,
116- scope : '=' ,
117- compile : function ( tElem , tAttrs )
11+ hex = value
12+ } ,
13+ $get : function ( )
11814 {
119- console . log ( '3 compile it. This is the original compiled DOM.' ) ;
12015 return {
121- pre : function preLink ( scope , iElement , iAttrs )
122- {
123- console . log ( '3 pre' ) ;
124- } ,
125- post : function postLink ( scope , iElement , iAttrs )
126- {
127- console . log ( '3 post' ) ;
128- }
16+ color : hex
12917 }
13018 }
13119 }
13220} )
13321
134- . controller ( "MainPageCtrl" , function ( $scope )
22+ . config ( function ( boxProvider )
13523{
136- $scope . mainPageMessage = "I am a new page. Sample." ;
24+ boxProvider . setColor ( "#3044b5" ) ;
13725} )
13826
139- . directive ( "buttonDirective ", function ( )
27+ . controller ( "AppCtrl ", function ( $scope , box )
14028{
141- return {
142- restrict : 'AE' ,
143- transclude : true ,
144- template : '<button class="btn btn-primary" type="button">' +
145- 'Accio Code <data-ng-transclude></data-ng-transclude>' +
146- '</button>'
147- }
29+ $scope . color = box . color ;
14830} )
0 commit comments