Top Banner
A Different Thought AngularJS Part-3
28
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A different thought   angular js part-3

A Different ThoughtAngularJS Part-3

Page 2: A different thought   angular js part-3

Agenda

Page 3: A different thought   angular js part-3

Agenda

1. Core Service

Page 4: A different thought   angular js part-3

Agenda

1. Core Servicea. $location

Page 5: A different thought   angular js part-3

Agenda

1. Core Servicea. $locationb. $http

Page 6: A different thought   angular js part-3

Agenda

1. Core Servicea. $locationb. $http

2. Custom Service

Page 7: A different thought   angular js part-3

Agenda

1. Core Servicea. $locationb. $http

2. Custom Service3. Custom Directive

Page 8: A different thought   angular js part-3

Agenda

1. Core Servicea. $locationb. $http

2. Custom Service3. Custom Directive4. Integrate TODO app with REST API

Page 9: A different thought   angular js part-3

About Me

Amit ThakkarTech Blogger @ CodeChutney.inJavaScript LoverWorking on MEAN Stack

Twitter: @amit_thakkar01LinkedIn: linkedin.com/in/amitthakkar01Facebook: facebook.com/amit.thakkar01

Page 10: A different thought   angular js part-3

Core Services - $location

(function (ng) { var todoApp = ng.module("todo", []); todoApp.controller("TODOController", ["$location", function ($location) { console.log($location.$$absUrl == "http://localhost:3000/TODO.html"); // true console.log($location.$$host == "localhost"); // true console.log($location.$$port == 3000); // true }]);})(angular);

Page 11: A different thought   angular js part-3

Core Services - $location

(function (ng) { var todoApp = ng.module("todo", []); todoApp.controller("TODOController", ["$location", function ($location) { console.log($location.$$absUrl == "http://localhost:3000/TODO.html"); // true console.log($location.$$host == "localhost"); // true console.log($location.$$port == 3000); // true }]);})(angular);

Page 12: A different thought   angular js part-3

Core Services - $location

(function (ng) { var todoApp = ng.module("todo", []); todoApp.controller("TODOController", ["$location", function ($location) { console.log($location.$$absUrl == "http://localhost:3000/TODO.html"); // true console.log($location.$$host == "localhost"); // true console.log($location.$$port == 3000); // true }]);})(angular);

Page 13: A different thought   angular js part-3

You can checkout Demo form: https://github.com/AmitThakkar/A-Different-Thought-AngualarJS

Page 14: A different thought   angular js part-3

Core Services - $http

(function (ng) { var todoApp = ng.module("todo", []); todoApp.controller("TODOController", ["$http", function ($http) { $http.get("todo") .success(function (todo) { todoController.tasks = todo; }) .error(function (error) { // Handle error here. console.log(error); }); }]);})(angular);

Page 15: A different thought   angular js part-3

Core Services - $http

(function (ng) { var todoApp = ng.module("todo", []); todoApp.controller("TODOController", ["$http", function ($http) { $http.get("todo") .success(function (todo) { todoController.tasks = todo; }) .error(function (error) { // Handle error here. console.log(error); }); }]);})(angular);

Page 16: A different thought   angular js part-3

Core Services - $http

(function (ng) { var todoApp = ng.module("todo", []); todoApp.controller("TODOController", ["$http", function ($http) { $http.get("todo") .success(function (todo) { todoController.tasks = todo; }) .error(function (error) { // Handle error here. console.log(error); }); }]);})(angular);

Page 17: A different thought   angular js part-3

You can checkout Demo form: https://github.com/AmitThakkar/A-Different-Thought-AngualarJS

Page 18: A different thought   angular js part-3

Custom Services - TodoService

(function (ng) { var todoApp = ng.module("todo"); todoApp.service("TODOService", ["$http", function ($http) { var API_URL = "todo"; var todoService = this; todoService.getTODOList = function () { return $http.get(API_URL); }; }]);})(angular);

Page 19: A different thought   angular js part-3

Custom Services - TodoService

(function (ng) { var todoApp = ng.module("todo"); todoApp.service("TODOService", ["$http", function ($http) { var API_URL = "todo"; var todoService = this; todoService.getTODOList = function () { return $http.get(API_URL); }; }]);})(angular);

Page 20: A different thought   angular js part-3

Custom Services - TodoService

(function (ng) { var todoApp = ng.module("todo"); todoApp.service("TODOService", ["$http", function ($http) { var API_URL = "todo"; var todoService = this; todoService.getTODOList = function () { return $http.get(API_URL); }; }]);})(angular);

Page 21: A different thought   angular js part-3

You can checkout Demo form: https://github.com/AmitThakkar/A-Different-Thought-AngualarJS

Page 22: A different thought   angular js part-3

var todoApp = ng.module("todo");todoApp.directive("keyEnter", function () { return { link: function (scope, element, attrs) { element.bind("keyup", function (event) { if (event.which === 13) { scope.$apply(function () { scope.$eval(attrs.keyEnter); }); event.preventDefault(); } }); } };});

Custom Directive - keyEnter

Page 23: A different thought   angular js part-3

var todoApp = ng.module("todo");todoApp.directive("keyEnter", function () { return { link: function (scope, element, attrs) { element.bind("keyup", function (event) { if (event.which === 13) { scope.$apply(function () { scope.$eval(attrs.keyEnter); }); event.preventDefault(); } }); } };});

Custom Directive - keyEnter

Page 24: A different thought   angular js part-3

var todoApp = ng.module("todo");todoApp.directive("keyEnter", function () { return { link: function (scope, element, attrs) { element.bind("keyup", function (event) { if (event.which === 13) { scope.$apply(function () { scope.$eval(attrs.keyEnter); }); event.preventDefault(); } }); } };});

Custom Directive - keyEnter

Page 25: A different thought   angular js part-3

You can checkout Demo form: https://github.com/AmitThakkar/A-Different-Thought-AngualarJS

Page 26: A different thought   angular js part-3

TODO App with RESP API

You can checkout Demo form: https://github.com/AmitThakkar/A-Different-Thought-AngualarJS

Page 27: A different thought   angular js part-3

Questions??

Page 28: A different thought   angular js part-3

References:Service in AngularJS