Guest User

Untitled

a guest
Sep 15th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. ----------------------------------display all products--------------------------------------
  2.  
  3. var app = angular.module('myApp', []);
  4. app.controller('myCtrl', function($scope) {
  5. var imgPath = "img/";
  6. //add your $scope variable products here with below provided product details.
  7. $scope.products = [{name : "Happy Cycle",
  8. discount:"20%",
  9. price: "2500",
  10. brand : "Wheels",
  11. addedToCart:false,
  12. image : imgPath + "cycle.jpg",
  13. quantity:0},
  14. {name : "Kids Shoes",
  15. discount:"10%",
  16. price: "1460",
  17. brand : "Feel Good",
  18. addedToCart:false,
  19. image : imgPath + "shoes.jpg",
  20. quantity:0},
  21. {name : "Polo Baby Care Dress",
  22. discount:"20%",
  23. price: "2500",
  24. brand : "Super Hero",
  25. addedToCart:false,
  26. image : imgPath + "shirt.jpg",
  27. quantity:0}
  28. ];
  29. });
  30.  
  31. /*
  32. -----------------
  33. Product Details
  34. -----------------
  35. product1
  36. {name : "Happy Cycle",
  37. discount:"20%",
  38. price: "2500",
  39. brand : "Wheels",
  40. addedToCart:false,
  41. image : imgPath + "cycle.jpg",
  42. quantity:0},
  43.  
  44. product2
  45. name : "Kids Shoes",
  46. discount:"10%",
  47. price: "1460",
  48. brand : "Feel Good",
  49. addedToCart:false,
  50. image : imgPath + "shoes.jpg",
  51. quantity:0
  52.  
  53. product3
  54. name : "Polo Baby Care Dress",
  55. discount:"20%",
  56. price: "2500",
  57. brand : "Super Hero",
  58. addedToCart:false,
  59. image : imgPath + "shirt.jpg",
  60. quantity:0
  61.  
  62. */
  63.  
  64. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  65.  
  66. //add to cart
  67.  
  68. var app = angular.module('myApp', []);
  69. app.controller('myCtrl', function($scope) {
  70. var imgPath = "img/";
  71. $scope.quantity=0;
  72. $scope.products = [
  73. {
  74. name : "Happy Cycle",
  75. discount:"20%",
  76. price: "2500",
  77. brand : "Wheels",
  78. addedToCart:false,
  79. image : imgPath + "cycle.jpg",
  80. quantity:0
  81. },
  82. {
  83. name : "Kids Shoes",
  84. discount:"10%",
  85. price: "1460",
  86. brand : "Feel Good",
  87. addedToCart:false,
  88. image : imgPath + "shoes.jpg",
  89. quantity:0
  90. },
  91. {
  92. name : "Polo Baby Care Dress",
  93. discount:"20%",
  94. price: "2500",
  95. brand : "Super Hero",
  96. addedToCart:false,
  97. image : imgPath + "shirt.jpg",
  98. quantity:0
  99. },
  100. ]
  101. $scope.addToCart = function(){
  102. alert("Product added to Cart successfully");
  103. return "success";
  104. }
  105. });
  106.  
  107. -------------------------------------------------------------------------------------------------------------------------------
  108.  
  109. internals
  110.  
  111. ------------------------------------------------------------------------------
  112.  
  113. sqaure root and cube root using services
  114.  
  115. // Add your code here!
  116.  
  117. var myApp = angular.module('myApp', []);
  118.  
  119. // define MathService here
  120. myApp.service('MathService', function() {
  121. //define all the arithmetic functions here like add, subtract. multiply and divide here
  122. this.multiply = function(num1,num2){
  123. return num1*num2;
  124. }
  125. });
  126.  
  127. // define CalculatorService here which uses Math service
  128. myApp.service('CalculatorService', function(MathService) {
  129. // consume MathService multiply function for getting square and cube of the parameter
  130. this.square = function(a) {
  131. return MathService.multiply(a,a);
  132. };
  133. this.cube = function(a) {
  134. return MathService.multiply(a,MathService.multiply(a,a));
  135. };
  136.  
  137. });
  138.  
  139. // define CalculatorController here
  140. myApp.controller('CalculatorController', function($scope, CalculatorService) {
  141. $scope.answer = 0;
  142. $scope.num=0;
  143. // consume CalculatorService- square and cube function for getting square of the input
  144. // set the result in scope variable answer
  145. $scope.Square = function() {
  146. $scope.answer = CalculatorService.square($scope.num);
  147. }
  148.  
  149. $scope.Cube = function() {
  150. $scope.answer= CalculatorService.cube($scope.num);
  151. }
  152. });
  153.  
  154. --------------------------------------------------------------------------
  155.  
  156. cube with factory
  157.  
  158. var myApp = angular.module('myApp', []);
  159.  
  160. myApp.factory('MathFactory', function() {
  161. //define all the arithmetic functions here like add, subtract. multiply and divide here
  162. var test={};
  163. test.multiply = function(num1,num2){
  164. return num1*num2;
  165. }
  166. return test;
  167. });
  168.  
  169. // define CalculatorService here which uses Math service
  170. myApp.factory('CalculatorFactory', function(MathFactory) {
  171. // consume MathService multiply function for getting square and cube of the parameter
  172. var res={};
  173. res.square = function(a) {
  174. return MathFactory.multiply(a,a);
  175. };
  176. res.cube = function(a) {
  177. return MathFactory.multiply(a,MathFactory.multiply(a,a));
  178. };
  179. return res;
  180. });
  181.  
  182. // define CalculatorController here
  183. myApp.controller('CalculatorController', function($scope, CalculatorFactory) {
  184. $scope.answer = 0;
  185. $scope.num=0;
  186. // consume CalculatorService- square and cube function for getting square of the input
  187. // set the result in scope variable answer
  188. $scope.Square = function() {
  189. $scope.answer = CalculatorFactory.square($scope.num);
  190. };
  191.  
  192. $scope.Cube = function() {
  193. $scope.answer= CalculatorFactory.cube($scope.num);
  194. };
  195. });
  196.  
  197. ---------------------------------------------
  198.  
  199. try it out with constants
  200.  
  201. var myApp = angular.module('myApp', []);
  202. var res={};
  203. res.cmp_url='TCS';
  204. res.cmp_md='tcs';
  205. res.cmp1_url='TCS';
  206. res.cmp1_md='tcs';
  207. res.cmp2_url='TCS';
  208. res.cmp2_md='tcs';
  209.  
  210. myApp.constant('app_api',res);
  211. // define CalculatorController here
  212. myApp.controller('mainCtrl', function($scope,app_api) {
  213. console.log(app_api);
  214. $scope.app_api = app_api;
  215. });
  216.  
  217. --------------------------------------------------------------------
  218.  
  219. scope and rootScope
  220.  
  221. // Write your code here.
  222. var myApp = angular.module('myApp', []);
  223.  
  224. myApp.controller('RController', function($scope,$rootScope){
  225. $scope.color = 'Red';$rootScope.color = 'White';
  226. });
  227.  
  228. myApp.controller('GController', function($scope,$rootScope){
  229. $scope.color = 'Blue';$rootScope.color = 'White';
  230. });
  231.  
  232. myApp.controller('BController', function($scope,$rootScope){
  233. $rootScope.color = 'White';
  234. $scope.color='';
  235. });
  236.  
  237. jQuery
  238.  
  239. _------------------------------------------------------------------------
  240.  
  241. EVENT HANDLING
  242.  
  243. function login() {
  244. var user = $("#username").val();
  245. var pass = $("#password").val();
  246. if(user == "admin" && pass == "password"){
  247. alert("You are a valid user");
  248. }else{
  249. alert("You are not a valid user")
  250. }
  251. };
  252.  
  253. ---------------------------------------------------------------------------
  254.  
  255. Addition of number
  256.  
  257. function add() {
  258. var num1 = $("#num1").val();
  259. var num2 = $("#num2").val();
  260. var res = parseInt(num1)+parseInt(num2)
  261. console.log(num1+" + "+num2+" = "+res);
  262. $("#total").val(res);
  263. };
  264.  
  265. ------------------------------------------------------
  266.  
  267. DOM manipulation
  268.  
  269. function login() {
  270. var user = $("#username").val();
  271. var pass = $("#password").val();
  272. if(user == "admin" && pass == "password"){
  273. doRedirect("home.html");
  274. }else{
  275. alert("You are not a valid user")
  276. }
  277. };
  278.  
  279. ------------------------------------------------------------------------
  280.  
  281. Animations
  282.  
  283. function login() {
  284. var user = $("#username").val();
  285. var pass = $("#password").val();
  286. if(user == "admin" && pass == "password"){
  287. doRedirect("home.html");
  288. }else{
  289. alert("You are not a valid user")
  290. }
  291. };
  292.  
  293. function hover1(){
  294.  
  295. $("item1-des").slideToggle();
  296. };
  297.  
  298. function hover2(){
  299. $("item2-des").slideToggle();
  300.  
  301. };
  302.  
  303. function big(){
  304. $("#buy").animate({height:"300px",width : "300px"});
  305.  
  306. };
  307.  
  308. function doRedirect(href) {
  309.  
  310. window.location = href;
  311.  
  312. };
  313.  
  314. -------------------------------------------------------
  315.  
  316. Ajax call
  317.  
  318. function login() {
  319. var user = $("#username").val();
  320. var pass = $("#password").val();
  321. if(user == "admin" && pass == "password"){
  322. doRedirect("home.html");
  323. }else{
  324. alert("You are not a valid user")
  325. }
  326. };
  327.  
  328. function hover1(){
  329.  
  330. $("#item1-des").slideToggle();
  331. };
  332.  
  333. function hover2(){
  334. $("#item2-des").slideToggle();
  335.  
  336. };
  337.  
  338. function big(){
  339. $("#buy").animate({height:"300px",width : "300px"});
  340.  
  341. };
  342.  
  343. function load_des() {
  344. $("#item1-des").load("https://codepen.io/anon/pen/KyRbKM.html");
  345.  
  346. };
  347.  
  348. function doRedirect(href) {
  349.  
  350. window.location = href;
  351.  
  352. };
  353.  
  354. _------_----------------------------------------------------------------------------------
  355.  
  356. JavaScript
  357.  
  358. Generate random characters
  359.  
  360. var element= document.getElementById('num').value;
  361. var val = Math.random().toString(36).replace('0.','').substr(0,element);
  362. document.getElementById('result').innerHTML=val;
  363. console.log(val);
  364. //Type your code here.
  365. return val;
  366.  
  367. ---------------------------------------------
  368.  
  369. Fibonacci Series
  370.  
  371. function fibonacciSequence(input) {
  372.  
  373. var v1=0,v2=1,v3;
  374. var res=[0,1];
  375.  
  376. for(var i = 3;i<=input+1;i++){
  377.  
  378. v3=v1+v2;
  379.  
  380. v1=v2;
  381.  
  382. v2=v3;
  383. res.push(v3);
  384. }
  385.  
  386. return res;
  387. }
  388.  
  389. -------------------------
  390.  
  391. Dropdown
  392.  
  393. function runList(){
  394. //Type your code here.
  395. var select = document.getElementById('list');
  396. var option = document.createElement('option');
  397.  
  398. option.innerHTML="japan";
  399. option.value="japan";
  400.  
  401. select.appendChild(option);
  402. }
  403.  
  404. ------------------------------------------------------------------------------------
  405.  
  406. to read user data from from
  407.  
  408. function myFunction() {
  409. // Type your code here.
  410. var name = document.getElementById("myname").value;
  411. var phone = document.getElementById("myphone").value;
  412. var country = document.getElementById("mycontry").value;
  413. var mail = document.getElementById("mymail").value;
  414. var res=name+","+phone+","+country+","+mail;
  415. alert(res);
  416. return res;//Enter your return statement here
  417. }
  418.  
  419. ----------------------------------------------------
  420.  
  421. simple calculator
  422.  
  423. function update(value) {
  424. //Type the code here.
  425. var out = document.getElementById("screen").value;
  426. out = out+""+value;
  427. document.getElementById("screen").value = out;
  428. }
  429.  
  430. function result() {
  431. //Type the code here.
  432. var out = document.getElementById("screen").value;
  433. out = eval(out);
  434. document.getElementById("screen").value = out;
  435. }
  436.  
  437. function reset() {
  438. //Type the code here.
  439. document.getElementById("screen").value = "";
  440. }
Add Comment
Please, Sign In to add comment