Last active
January 16, 2019 14:13
-
-
Save var-bin/c0207c7ccd092943331e9fb1cd5d5071 to your computer and use it in GitHub Desktop.
lazyLoad modules in AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// home.module.js | |
"use strict"; | |
import angular from "angular"; | |
import { homeRouting } from "./home.module.routing"; | |
import { BlogService } from "../blog/blog.service"; | |
const HOME_MODULE = angular | |
.module("homeModule", []) | |
.service("BlogService", BlogService) | |
.config(homeRouting); | |
export { HOME_MODULE }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/src/pages/home/home.module.js | |
+++ b/src/pages/home/home.module.js | |
@@ -5,8 +5,11 @@ | |
import angular from "angular"; | |
import { homeRouting } from "./home.module.routing"; | |
+import { BlogService } from "../blog/blog.service"; | |
+ | |
const HOME_MODULE = angular | |
.module("homeModule", []) | |
+ .service("BlogService", BlogService) | |
.config(homeRouting); | |
export { HOME_MODULE }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.module.js | |
"use strict"; | |
import angular from "angular"; | |
class HomeIndexController { | |
constructor(BlogService) { | |
this.title = "HomeComponent"; | |
this.BlogService = BlogService; | |
this.repos = []; | |
} | |
$onInit() { | |
this.getArticles(); | |
} | |
getArticles() { | |
this.BlogService.getData() | |
.then((data) => { | |
this.repos = data; | |
}); | |
} | |
} | |
HomeIndexController.$inject = ["BlogService"]; | |
class HomeIndexComponent { | |
constructor() { | |
this.template = require("./index.view.html"); | |
this.controller = HomeIndexController; | |
} | |
} | |
const HOME_INDEX_MODULE = angular | |
.module("home.module", []) | |
.component("homeComponent", new HomeIndexComponent()); | |
export { HOME_INDEX_MODULE }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/src/pages/home/index/index.module.js | |
+++ b/src/pages/home/index/index.module.js | |
@@ -5,11 +5,26 @@ | |
import angular from "angular"; | |
class HomeIndexController { | |
- constructor() { | |
+ constructor(BlogService) { | |
this.title = "HomeComponent"; | |
+ this.BlogService = BlogService; | |
+ this.repos = []; | |
+ } | |
+ | |
+ $onInit() { | |
+ this.getArticles(); | |
+ } | |
+ | |
+ getArticles() { | |
+ this.BlogService.getData() | |
+ .then((data) => { | |
+ this.repos = data; | |
+ }); | |
} | |
} | |
+HomeIndexController.$inject = ["BlogService"]; | |
+ | |
class HomeIndexComponent { | |
constructor() { | |
this.template = require("./index.view.html"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment