Skip to content

Commit fea36bc

Browse files
committed
"Components"
1 parent 6f11258 commit fea36bc

File tree

2 files changed

+252
-13
lines changed

2 files changed

+252
-13
lines changed

index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,41 @@ <h3>Age:{{$last}}}</h3>
6868
</li>
6969
<!-- <li ng-repeat="user in myCtrl.serverData.testArray track by $index"></li> -->
7070
</ul>
71+
<h1>Massages</h1>
72+
<h2>New massages:{{myCtrl.getMassage()}}</h2>
73+
<h3>Massages count:{{myCtrl.getMassageCount()}}</h3>
74+
75+
<form action="#"
76+
ng-controller="massagesController as massagesController"
77+
>
78+
</form>
79+
<my-massager
80+
title="Send Massege Form"
81+
on-massage-sent="massagesController.sendMassage(massage)"
82+
></my-massager>
7183
</div>
84+
85+
<h1
86+
style="position:fixed;right:50px;bottom:50px;"
87+
>^^ Scroll top ^^</h1>
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
72107
</body>
73108
</html>

js/main.js

Lines changed: 217 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
(function(){
22
"use strict";
33
angular.module("app",[
4-
"price"
4+
"price",
5+
"toHtml",
6+
"myComponent",
7+
"ScrollService",
8+
"scrollToTop"
59
]).run(function($templateCach){
6-
$templateCach.put('myTamplate.html','This is the<br/>');
10+
$templateCach.put('myTamplate.html','This is the<br/> contant of');
711
});
812
})();
913

@@ -24,6 +28,7 @@
2428
"use strict";
2529
angular.module("toHtml",[])
2630
.filter("toHtml",toHtml);
31+
2732
toHtml.$inject=["$sce"];
2833

2934
function toHtml($sce){
@@ -37,8 +42,8 @@
3742
"use strict";
3843
angular.module("app")
3944
.controller("myCtrl",myCtrl);
40-
myCtrl.$inject=["$scope","$filter","$http","$q","$sce","$templateCache","$interval"];
41-
function myCtrl($scope,$filter,$http,$q,$sce,$templateCache,$interval){
45+
myCtrl.$inject=["$scope","$filter","$http","$q","$sce","$templateCache","$interval","testConstant","testConstant2","massage","massages","ScrollService"];
46+
function myCtrl($scope,$filter,$http,$q,$sce,$templateCache,$interval,testConstant,testConstant2,massage,massages){
4247
var myCtrl=this;
4348
myCtrl.price=$filter("price")(25,"#");
4449
myCtrl.serverData={};
@@ -52,20 +57,33 @@
5257
myCtrl.selectedOption="";
5358
myCtrl.imageSrc="";
5459

55-
myCtrl.options={
56-
{value:"",lable:"Select item"},
57-
{value:"item1",lable:"Select item1"},
58-
{value:"item2",lable:"Select item2"},
59-
{value:"item3",lable:"Select item3"},
60-
{value:"item4",lable:"Select item4"},
61-
{value:"item5",lable:"Select item5"},
62-
{value:"item6",lable:"Select item6"},
60+
console.log(testConstant);
61+
console.log(testConstant2);
62+
63+
myCtrl.options=[
64+
{value:"",label:"Select item"},
65+
{value:"item1",label:"Item1 label"},
66+
{value:"item2",label:"Item2 label"},
67+
{value:"item3",label:"Item3 label"},
68+
{value:"item4",label:"Item4 label"},
69+
{value:"item5",label:"Item5 label"},
70+
{value:"item6",label:"Item6 label"},
6371

64-
}
72+
]
6573

6674
myCtrl.onBlur=onBlur;
6775
myCtrl.askUser=askUser;
6876
myCtrl.usersFilterMethod=usersFilterMethod;
77+
myCtrl.getMassage=getMassage;
78+
myCtrl.getMassagesCount=getMassagesCount;
79+
80+
function getMassage(){
81+
return massages.massage;
82+
}
83+
84+
function getMassagesCount(){
85+
return massages.list.length;
86+
}
6987

7088
function onBlur($event){
7189
console.log($event);
@@ -110,6 +128,192 @@
110128

111129
})();
112130

131+
(function (){
132+
"use strict";
133+
134+
angular.module("app")
135+
.constant("testConstant","testConstantValue")
136+
.constant("testConstant2",{
137+
"key1":"value1",
138+
"key2":"value2"
139+
})
140+
})();
141+
142+
(function(){
143+
angular.module("app")
144+
.value("massage","")
145+
.value("massages",{
146+
list:[]
147+
})
148+
})();
149+
150+
(function(){
151+
"use strict";
152+
153+
angular.module("app")
154+
.controller("massagesController",massagesController);
155+
156+
massagesController.$inject=["massage","massages","ScrollService"];
157+
function massagesController(massage,massages,ScrollService){
158+
var massagesController=this;
159+
160+
massagesController.massageField="";
161+
162+
massagesController.sendMassage=sendMassage;
163+
164+
function sendMassage(newMassage){
165+
massage.list.push(newMassage);
166+
massages.massage=newMassage;
167+
}
168+
}
169+
})();
170+
171+
(function(){
172+
"use strict";
173+
174+
angular.module("ScrollService",[])
175+
.service("ScrollService",ScrollService);
176+
177+
ScrollService.$inject=["testFactory"];
178+
function ScrollService(testFactory){
179+
return{
180+
scrollTop:scrollTop
181+
}
182+
183+
function scrollTop(position){
184+
console.log(testFactory);
185+
testFactory.method();
186+
$("body").animate({"scrollTop":position},500);
187+
}
188+
}
189+
190+
191+
})();
192+
193+
(function(){
194+
"use strict";
195+
angular.module("app")
196+
.factory("testFactory",testFactory);
197+
198+
function testFactory(){
199+
return{
200+
key1:"value1",
201+
key2:"value2",
202+
obj:{"test":"rest"},
203+
method:method
204+
}
205+
206+
function scrollTop(position){
207+
$("html,body").animate({"scrollTop":position},500);
208+
}
209+
}
210+
211+
})();
212+
213+
(function(){
214+
"use strict";
215+
216+
angular.module("app")
217+
.component("myMassanger",myMassanger());
218+
219+
function myMassanger(){
220+
myMassangerCtrl.$inject=["massages"];
221+
return{
222+
templateUrl:"componentTemplate.html",
223+
//template:"<div><h1>{{myMassanger.myTitle}}</h1></div>",
224+
controller:myMassangerCtrl,
225+
controllerAs:"myMassanger",
226+
transclude:false,
227+
bindings:{
228+
title:"@",
229+
onMassageSent:"&"
230+
}
231+
}
232+
233+
function myMassangerCtrl(){
234+
var myMassangerCtrl=this;
235+
236+
myMassangerCtrl.massageField="";
237+
238+
myMassangerCtrl.sendMassage=sendMassage;
239+
240+
function sendMassage(massage){
241+
myMassangerCtrl.onMassageSent({"massage":massage});
242+
massages.massage=massage;
243+
massages.list.push(massage);
244+
}
245+
}
246+
}
247+
248+
})();
249+
250+
251+
(function(){
252+
"use strict";
253+
254+
angular.module("scrollToTop",["ScrollService"])
255+
.directive("scrollToTop",scrollToTop);
256+
257+
scrollToTop.$inject=["ScrollService"];
258+
259+
function scrollToTop(ScrollService){
260+
return {
261+
restrict:"A",
262+
link:link
263+
//scope:false
264+
}
265+
function link($scope,$element){
266+
$element.on("click",function(){
267+
ScrollService.scrollToTop(0);
268+
})
269+
270+
}
271+
}
272+
273+
274+
})();
275+
276+
277+
(function(){
278+
"use strict";
279+
280+
angular.module("app")
281+
.factory("myInterceptors",myInterceptors);
282+
.config("$httpProvider",interceptorsConfig);
283+
284+
myInterceptors.$inject=["$q"];
285+
function myInterceptors($q){
286+
return{
287+
request:function(config){
288+
console.log(config);
289+
return config;
290+
},
291+
response:function(response){
292+
return response;
293+
},
294+
requestError:function(rejectReason){
295+
return $q.reject(rejectReason);
296+
},
297+
responseError:function(response){
298+
return $q.reject(response);
299+
}
300+
}
301+
}
302+
303+
interceptorsConfig.$inject=["$httpProvider"];
304+
function interceptorsConfig($httpProvider){
305+
$httpProvider.interceptors.push('myInterceptors');
306+
}
307+
308+
})();
309+
310+
311+
312+
313+
314+
315+
316+
113317

114318

115319

0 commit comments

Comments
 (0)