Guest User

Untitled

a guest
Sep 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.80 KB | None | 0 0
  1. [9/11, 5:33 PM] ‪+91 82668 33460‬: ----------------------------------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. }
  441. [9/14, 8:45 AM] ‪+91 82668 33460‬: angular diectives
  442.  
  443. -----------------------------------------------------------------
  444.  
  445. get user detail $http 
  446.  
  447. var app = angular.module('myApp', []);
  448. app.controller('myCtrl', function($scope,$http) {
  449. //Define scope variable users here
  450. $scope.users;
  451. //Use http service that consumes https://jsonplaceholder.typicode.com/users
  452. $scope.users=$http.get('https://jsonplaceholder.typicode.com/users');
  453. });
  454.  
  455. ---------------------------------------------------------------------------------------
  456.  
  457. form validations
  458.  
  459. var app = angular.module('myApp', []);
  460. app.controller('myCtrl', function($scope) {
  461. var imgPath = "img/";
  462. $scope.dtsinCart=0;
  463. $scope.products = [
  464. {
  465. name : "Happy Cycle",
  466. discount:"20%",
  467. price: "2500",
  468. brand : "Wheels",
  469. addedToCart:false,
  470. image : imgPath + "cycle.jpg",
  471. quantity:0
  472. },
  473. {
  474. name : "Kids Shoes",
  475. discount:"10%",
  476. price: "1460",
  477. brand : "Feel Good",
  478. addedToCart:false,
  479. image : imgPath + "shoes.jpg",
  480. quantity:0
  481. },
  482. {
  483. name : "Polo Baby Care Dress",
  484. discount:"20%",
  485. price: "2500",
  486. brand : "Super Hero",
  487. addedToCart:false,
  488. image : imgPath + "shirt.jpg",
  489. quantity:0
  490. },
  491. ];
  492. $scope.addToCart=function(){
  493. alert('Product Added to Cart successfully');
  494. return "success";
  495. }
  496. //add your code for registerUser which return successful message
  497. $scope.registerUser = function(){
  498. alert('Registration Successful');
  499. return "successful";
  500. }
  501.  
  502. });
  503.  
  504. -----------------------------------------------------
  505.  
  506. display product image
  507.  
  508. var app = angular.module('myApp', []);
  509. app.controller('myCtrl', function($scope) {
  510. $scope.quantity=0;
  511. //Add image property to the products and the image should have the url of images
  512. $scope.products = [
  513. {
  514. name : "Happy Cycle",
  515. discount:"20%",
  516. price: "2500",
  517. brand : "Wheels",
  518. addedToCart:false,
  519. image:'img/cycle.jpg',
  520. quantity:0
  521. },
  522. {
  523. name : "Kids Shoes",
  524. discount:"10%",
  525. price: "1460",
  526. brand : "Feel Good",
  527. addedToCart:false,
  528. image:'img/cycle.jpg',
  529. quantity:0
  530. },
  531. {
  532. name : "Polo Baby Care Dress",
  533. discount:"20%",
  534. price: "2500",
  535. brand : "Super Hero",
  536. addedToCart:false,
  537. image:'img/cycle.jpg',
  538. quantity:0
  539. },
  540. ]
  541. $scope.addToCart=function(){
  542. alert('Product Added to Cart successfully')
  543. return "success";
  544.  
  545. }
  546. });
  547.  
  548. -----------------------------------------------------------------------------------------
  549.  
  550. hello with angular js
  551.  
  552. var myApp = angular.module('myApp',[]);
  553. myApp.controller('myCtrl',function($scope){
  554. $scope.fullName = "Harry Potter";
  555. });
  556.  
  557. ------------------------------------------------------------------
  558.  
  559. sort and search product
  560.  
  561. var app = angular.module('myApp', []);
  562. app.controller('myCtrl', function($scope) {
  563. var imgPath = "img/";
  564. $scope.priceFilter='';
  565. $scope.dtsinCart=0;
  566. $scope.products = [
  567. {
  568. name : "Happy Cycle",
  569. discount:"20%",
  570. price: 2500,
  571. brand : "Wheels",
  572. addedToCart:false,
  573. image : imgPath + "cycle.jpg",
  574. quantity:0
  575. },
  576. {
  577. name : "Polo Baby Care Dress",
  578. discount:"20%",
  579. price: 500,
  580. brand : "Super Hero",
  581. addedToCart:false,
  582. image : imgPath + "shirt.jpg",
  583. quantity:0
  584. },
  585. {
  586. name : "Kids Shoes",
  587. discount:"10%",
  588. price: 1000,
  589. brand : "Feel Good",
  590. addedToCart:false,
  591. image : imgPath + "shoes.jpg",
  592. quantity:0
  593. }
  594.  
  595. ];
  596. $scope.addToCart=function(){
  597. alert('Product Added to Cart successfully')
  598. return "success";
  599. }
  600. //create scope variable options that has 'Low Price to High' and 'High Price to Low' values.
  601. $scope.options = ['Low Price to High' , 'High Price to Low'];
  602.  
  603. //add selectPriceFilter function that assign scope priceFilter to true / false based on condition
  604. $scope.selectPriceFilter = function(){};
  605.  
  606. });
  607.  
  608. -----------------------------------------------------------------------------------------------------------------------------
  609.  
  610. even or oddd
  611.  
  612. var app = angular.module('myApp', []);
  613. app.controller('myCtrl', function($scope) {
  614. //add your code here
  615. $scope.number1=9;
  616. $scope.number2=9;
  617. $scope.odd_even = function(number){
  618. return number%2==0?'even':'odd';
  619. };
  620. });
  621.  
  622. ------------------------------------------------------
  623.  
  624. hello name
  625.  
  626. var app = angular.module('myApp', []);
  627. app.controller('myCtrl', function($scope) {
  628. //write your code here
  629. $scope.fullName='anuj';
  630. });
  631.  
  632. -------------------------------------------------------------------
  633.  
  634. firstname lastname
  635.  
  636. Hello {{first_name+" "+last_name}} !
  637.  
  638. var app = angular.module('myApp', []);
  639. app.controller('myCtrl', function($scope) {
  640. //write your code here
  641. $scope.first_name ='mean';
  642. $scope.last_name ='mom';
  643. });
  644.  
  645. ------------------------------------------------------------------------
  646.  
  647. display all products
  648.  
  649. var app = angular.module('myApp', []);
  650. app.controller('myCtrl', function($scope) {
  651. var imgPath = "img/";
  652. //add your $scope variable products here with below provided product details.
  653. $scope.products = [{name : "Happy Cycle",
  654. discount:"20%",
  655. price: "2500",
  656. brand : "Wheels",
  657. addedToCart:false,
  658. image : imgPath + "cycle.jpg",
  659. quantity:0},
  660. {name : "Kids Shoes",
  661. discount:"10%",
  662. price: "1460",
  663. brand : "Feel Good",
  664. addedToCart:false,
  665. image : imgPath + "shoes.jpg",
  666. quantity:0},
  667. {name : "Polo Baby Care Dress",
  668. discount:"20%",
  669. price: "2500",
  670. brand : "Super Hero",
  671. addedToCart:false,
  672. image : imgPath + "shirt.jpg",
  673. quantity:0}
  674. ];
  675. });
  676.  
  677. /*
  678. -----------------
  679. Product Details
  680. -----------------
  681. product1
  682. {name : "Happy Cycle",
  683. discount:"20%",
  684. price: "2500",
  685. brand : "Wheels",
  686. addedToCart:false,
  687. image : imgPath + "cycle.jpg",
  688. quantity:0},
  689.  
  690. product2
  691. name : "Kids Shoes",
  692. discount:"10%",
  693. price: "1460",
  694. brand : "Feel Good",
  695. addedToCart:false,
  696. image : imgPath + "shoes.jpg",
  697. quantity:0
  698.  
  699. product3
  700. name : "Polo Baby Care Dress",
  701. discount:"20%",
  702. price: "2500",
  703. brand : "Super Hero",
  704. addedToCart:false,
  705. image : imgPath + "shirt.jpg",
  706. quantity:0
  707.  
  708. */
  709.  
  710. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  711.  
  712. //add to cart
  713.  
  714. var app = angular.module('myApp', []);
  715. app.controller('myCtrl', function($scope) {
  716. var imgPath = "img/";
  717. $scope.quantity=0;
  718. $scope.products = [
  719. {
  720. name : "Happy Cycle",
  721. discount:"20%",
  722. price: "2500",
  723. brand : "Wheels",
  724. addedToCart:false,
  725. image : imgPath + "cycle.jpg",
  726. quantity:0
  727. },
  728. {
  729. name : "Kids Shoes",
  730. discount:"10%",
  731. price: "1460",
  732. brand : "Feel Good",
  733. addedToCart:false,
  734. image : imgPath + "shoes.jpg",
  735. quantity:0
  736. },
  737. {
  738. name : "Polo Baby Care Dress",
  739. discount:"20%",
  740. price: "2500",
  741. brand : "Super Hero",
  742. addedToCart:false,
  743. image : imgPath + "shirt.jpg",
  744. quantity:0
  745. },
  746. ];
  747. $scope.addToCart = function(){
  748. alert("Product added to Cart successfully");
  749. return "success";
  750. }
  751. });
  752.  
  753. -------------------------------------------------------------------------------------------------------------------------------
  754.  
  755. internals
  756.  
  757. ------------------------------------------------------------------------------
  758.  
  759. sqaure root and cube root using services
  760.  
  761. // Add your code here!
  762.  
  763. var myApp = angular.module('myApp', []);
  764.  
  765. // define MathService here
  766. myApp.service('MathService', function() {
  767. //define all the arithmetic functions here like add, subtract. multiply and divide here
  768. this.multiply = function(num1,num2){
  769. return num1*num2;
  770. }
  771. });
  772.  
  773. // define CalculatorService here which uses Math service
  774. myApp.service('CalculatorService', function(MathService) {
  775. // consume MathService multiply function for getting square and cube of the parameter
  776. this.square = function(a) {
  777. return MathService.multiply(a,a);
  778. };
  779. this.cube = function(a) {
  780. return MathService.multiply(a,MathService.multiply(a,a));
  781. };
  782.  
  783. });
  784.  
  785. // define CalculatorController here
  786. myApp.controller('CalculatorController', function($scope, CalculatorService) {
  787. $scope.answer = 0;
  788. $scope.num=0;
  789. // consume CalculatorService- square and cube function for getting square of the input
  790. // set the result in scope variable answer
  791. $scope.Square = function() {
  792. $scope.answer = CalculatorService.square($scope.num);
  793. }
  794.  
  795. $scope.Cube = function() {
  796. $scope.answer= CalculatorService.cube($scope.num);
  797. }
  798. });
  799.  
  800. --------------------------------------------------------------------------
  801.  
  802. cube with factory
  803.  
  804. var myApp = angular.module('myApp', []);
  805.  
  806. myApp.factory('MathFactory', function() {
  807. //define all the arithmetic functions here like add, subtract. multiply and divide here
  808. var test={};
  809. test.multiply = function(num1,num2){
  810. return num1*num2;
  811. }
  812. return test;
  813. });
  814.  
  815. // define CalculatorService here which uses Math service
  816. myApp.factory('CalculatorFactory', function(MathFactory) {
  817. // consume MathService multiply function for getting square and cube of the parameter
  818. var res={};
  819. res.square = function(a) {
  820. return MathFactory.multiply(a,a);
  821. };
  822. res.cube = function(a) {
  823. return MathFactory.multiply(a,MathFactory.multiply(a,a));
  824. };
  825. return res;
  826. });
  827.  
  828. // define CalculatorController here
  829. myApp.controller('CalculatorController', function($scope, CalculatorFactory) {
  830. $scope.answer = 0;
  831. $scope.num=0;
  832. // consume CalculatorService- square and cube function for getting square of the input
  833. // set the result in scope variable answer
  834. $scope.Square = function() {
  835. $scope.answer = CalculatorFactory.square($scope.num);
  836. };
  837.  
  838. $scope.Cube = function() {
  839. $scope.answer= CalculatorFactory.cube($scope.num);
  840. };
  841. });
  842.  
  843. ---------------------------------------------
  844.  
  845. try it out with constants
  846.  
  847. var myApp = angular.module('myApp', []);
  848. var res={};
  849. res.cmp_url='';
  850. res.cmp_md='';
  851. res.cmp1_url='';
  852. res.cmp1_md='';
  853. res.cmp2_url='';
  854. res.cmp2_md='';
  855.  
  856. myApp.constant('app_api',res);
  857. // define CalculatorController here
  858. myApp.controller('myCtrl', function($scope,app_api) {
  859. console.log(app_api);
  860. $scope.app_api = app_api;
  861. $scope.cmp_name='';
  862. });
  863.  
  864. --------------------------------------------------------------------
  865.  
  866. watch
  867.  
  868. // write your code here
  869. var myApp = angular.module('myApp',[]);
  870. myApp.controller('myCtrl',function($scope){
  871. $scope.fullName = "Harry Potter";
  872. });
  873.  
  874. --------------------------------------------------------------------
  875.  
  876. scope and rootScope
  877.  
  878. // Write your code here.
  879. var myApp = angular.module('myApp', []);
  880.  
  881. myApp.controller('RController', function($scope,$rootScope){
  882. $scope.color = 'Red';$rootScope.color = 'White';
  883. });
  884.  
  885. myApp.controller('GController', function($scope,$rootScope){
  886. $scope.color = 'Blue';$rootScope.color = 'White';
  887. });
  888.  
  889. myApp.controller('BController', function($scope,$rootScope){
  890. $rootScope.color = 'White';
  891. $scope.color='';
  892. });
  893.  
  894. jQuery
  895.  
  896. _------------------------------------------------------------------------
  897.  
  898. EVENT HANDLING
  899.  
  900. function login() {
  901. var user = $("#username").val();
  902. var pass = $("#password").val();
  903. if(user == "admin" && pass == "password"){
  904. alert("You are a valid user");
  905. }else{
  906. alert("You are not a valid user")
  907. }
  908. };
  909.  
  910. ---------------------------------------------------------------------------
  911.  
  912. Addition of number
  913.  
  914. function add() {
  915. var num1 = $("#num1").val();
  916. var num2 = $("#num2").val();
  917. var res = parseInt(num1)+parseInt(num2)
  918. console.log(num1+" + "+num2+" = "+res);
  919. $("#total").val(res);
  920. };
  921.  
  922. ------------------------------------------------------
  923.  
  924. DOM manipulation
  925.  
  926. function login() {
  927. var user = $("#username").val();
  928. var pass = $("#password").val();
  929. if(user == "admin" && pass == "password"){
  930. doRedirect("home.html");
  931. }else{
  932. alert("You are not a valid user")
  933. }
  934. };
  935.  
  936. ------------------------------------------------------------------------
  937.  
  938. Animations
  939.  
  940. function login() {
  941. var user = $("#username").val();
  942. var pass = $("#password").val();
  943. if(user == "admin" && pass == "password"){
  944. doRedirect("home.html");
  945. }else{
  946. alert("You are not a valid user")
  947. }
  948. };
  949.  
  950. function hover1(){
  951.  
  952. $("item1-des").slideToggle();
  953. };
  954.  
  955. function hover2(){
  956. $("item2-des").slideToggle();
  957.  
  958. };
  959.  
  960. function big(){
  961. $("#buy").animate({height:"300px",width : "300px"});
  962.  
  963. };
  964.  
  965. function doRedirect(href) {
  966.  
  967. window.location = href;
  968.  
  969. };
  970.  
  971. -------------------------------------------------------
  972.  
  973. Ajax call
  974.  
  975. function login() {
  976. var user = $("#username").val();
  977. var pass = $("#password").val();
  978. if(user == "admin" && pass == "password"){
  979. doRedirect("home.html");
  980. }else{
  981. alert("You are not a valid user")
  982. }
  983. };
  984.  
  985. function hover1(){
  986.  
  987. $("#item1-des").slideToggle();
  988. };
  989.  
  990. function hover2(){
  991. $("#item2-des").slideToggle();
  992.  
  993. };
  994.  
  995. function big(){
  996. $("#buy").animate({height:"300px",width : "300px"});
  997.  
  998. };
  999.  
  1000. function load_des() {
  1001. $("#item1-des").load("https://codepen.io/anon/pen/KyRbKM.html");
  1002.  
  1003. };
  1004.  
  1005. function doRedirect(href) {
  1006.  
  1007. window.location = href;
  1008.  
  1009. };
  1010.  
  1011. _------_----------------------------------------------------------------------------------
  1012.  
  1013. JavaScript
  1014.  
  1015. Generate random characters
  1016.  
  1017. var element= document.getElementById('num').value;
  1018. var val = Math.random().toString(36).replace('0.','').substr(0,element);
  1019. document.getElementById('result').innerHTML=val;
  1020. console.log(val);
  1021. //Type your code here.
  1022. return val;
  1023.  
  1024. ---------------------------------------------
  1025.  
  1026. Fibonacci Series
  1027.  
  1028. function fibonacciSequence(input) {
  1029.  
  1030. var v1=0,v2=1,v3;
  1031. var res=[0,1];
  1032.  
  1033. for(var i = 3;i<=input+1;i++){
  1034.  
  1035. v3=v1+v2;
  1036.  
  1037. v1=v2;
  1038.  
  1039. v2=v3;
  1040. res.push(v3);
  1041. }
  1042.  
  1043. return res;
  1044. }
  1045.  
  1046. -------------------------
  1047.  
  1048. Dropdown
  1049.  
  1050. function runList(){
  1051. //Type your code here.
  1052. var select = document.getElementById('list');
  1053. var option = document.createElement('option');
  1054.  
  1055. option.innerHTML="japan";
  1056. option.value="japan";
  1057.  
  1058. select.appendChild(option);
  1059. }
  1060.  
  1061. ------------------------------------------------------------------------------------
  1062.  
  1063. to read user data from from
  1064.  
  1065. function myFunction() {
  1066. // Type your code here.
  1067. var name = document.getElementById("myname").value;
  1068. var phone = document.getElementById("myphone").value;
  1069. var country = document.getElementById("mycontry").value;
  1070. var mail = document.getElementById("mymail").value;
  1071. var res=name+","+phone+","+country+","+mail;
  1072. alert(res);
  1073. return res;//Enter your return statement here
  1074. }
  1075.  
  1076. ----------------------------------------------------
  1077.  
  1078. simple calculator
  1079.  
  1080. function update(value) {
  1081. //Type the code here.
  1082. var out = document.getElementById("screen").value;
  1083. out = out+""+value;
  1084. document.getElementById("screen").value = out;
  1085. }
  1086.  
  1087. function result() {
  1088. //Type the code here.
  1089. var out = document.getElementById("screen").value;
  1090. out = eval(out);
  1091. document.getElementById("screen").value = out;
  1092. }
  1093.  
  1094. function reset() {
  1095. //Type the code here.
  1096. document.getElementById("screen").value = "";
  1097. }
Add Comment
Please, Sign In to add comment