forked from colorfest/angularjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangularjstutorial.js
More file actions
148 lines (138 loc) · 3.1 KB
/
angularjstutorial.js
File metadata and controls
148 lines (138 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* use strict */
var app = angular.module('MyApp', ['ngRoute'])
app.config(function ($routeProvider)
{
$routeProvider
.when('/',
{
templateUrl: "partials/sample.html",
controller: "MainPageCtrl"
})
.when('/pageTwo',
{
template: '<div>This is page <strong>two</strong>!</div>'
})
.when('/calendar/:month/:day/:year',
{
templateUrl: "partials/calendar.html",
controller: "CalendarCtrl"
})
.otherwise(
{
template: '<div><strong>THERE IS NO PAGE HERE!</strong></div>'
})
})
.controller("CalendarCtrl", function ($scope, $routeParams)
{
$scope.model = {
message: "Date: " + $routeParams.month + " / "
+ $routeParams.day + " / "
+ $routeParams.year
}
})
.controller('MainController', function ($scope)
{
$scope.labelName = "New Button";
$scope.newElement = angular.element('<div class="btn btn-default">' +
$scope.labelName + '</div>');
})
.directive('compileDirective', function ($compile)
{
return {
restrict: 'E',
template: '<div>New compile template</div>',
controller: 'MainController',
link: function (scope, elm, attrs)
{
var compileIt = $compile(scope.newElement);
var content = compileIt(scope);
elm.append(content);
}
}
})
.directive('pageDirective', function ()
{
return {
restrict: 'E',
template: '<div>Here is a new button</div>',
controller: 'MainController',
scope: '=',
compile: function (tElem, tAttrs)
{
console.log('compile it. This is the original compiled DOM.');
return {
pre: function preLink (scope, iElement, iAttrs)
{
console.log('pre');
iElement.html('<div class="panel panel-default">Now a panel</div>');
},
post: function postLink (scope, iElement, iAttrs)
{
console.log('post');
iElement.append(scope.newElement);
}
}
}
}
})
.directive('pageDirectiveTwo', function ()
{
return {
restrict: 'E',
template: '<div>Here is a second button</div>',
controller: 'MainController',
scope: '=',
compile: function (tElem, tAttrs)
{
console.log('2 compile it. This is the original compiled DOM.');
return {
pre: function preLink (scope, iElement, iAttrs)
{
console.log('2 pre');
},
post: function postLink (scope, iElement, iAttrs)
{
console.log('2 post');
iElement.append(scope.newElement);
}
}
}
}
})
.directive('pageDirectiveThree', function ()
{
return {
restrict: 'E',
template: '<div>Here is a third button</div>',
controller: 'MainController',
scope: '=',
compile: function (tElem, tAttrs)
{
console.log('3 compile it. This is the original compiled DOM.');
return {
pre: function preLink (scope, iElement, iAttrs)
{
console.log('3 pre');
},
post: function postLink (scope, iElement, iAttrs)
{
console.log('3 post');
}
}
}
}
})
.controller("MainPageCtrl", function ($scope)
{
$scope.mainPageMessage = "I am a new page. Sample.";
})
.directive("buttonDirective", function ()
{
return {
restrict: 'AE',
transclude: true,
template: '<button class="btn btn-primary" type="button">' +
'Accio Code <data-ng-transclude></data-ng-transclude>' +
'</button>'
}
})