Giter Club home page Giter Club logo

angularjs-boilerplate's Introduction

angularjs-boilerplate

This repo is a boilerplate app structure on building structured web apps with angularjs 1.x. It brings modularization to angular.js using require.js.

Installation

  • Clone the repo
  • Run bower install

Directory Structure

.
├── app
│   ├── css
│   │   └── app.css                 # app css file
│   ├── img                         # image folder
│   ├── js
│   │   ├── app.js                  # the definition of app module
│   │   ├── controllers             # folder contains controllers
│   │   │   ├── HelloController.js
│   │   │   ├── index.js
│   │   │   └── module.js
│   │   ├── directives              # folder contains custom directives
│   │   │   ├── index.js
│   │   │   └── module.js
│   │   ├── filters                 # folder contains custom filters
│   │   │   ├── index.js
│   │   │   └── module.js
│   │   ├── main.js                 # entry point of angular app
│   │   ├── routes.js               # file contains angular route definitions
│   │   └── services                # folder contains services
│   │       ├── index.js
│   │       └── module.js
│   └── views                       # folder contains angular templates
│       └── hello.html
├── bower.json
└── index.html

Modules

In this structure, all modules have index.js & module.js files. module.js file contains the module definition like the following;

// module.js
define(['angular'], function(angular) {

    'use strict';
    return angular.module('app.controllers', []);
});

// index.js
define([

    './HelloController'
    // module files should be included here

], function() {});

Adding a new module

Adding a new module to the system is really easy.

  • Create a folder inside app folder
$ mkdir custom_module
  • Add module.js & index.js files
// module.js
define(['angular'], function(angular) {

    'use strict';
    return angular.module('custom_module', []);
});

// index.js
define([

    './FileInsideCustomModule'

], function(){});
  • Add the dependency into app
define([

    'angular',
    'angularRoute',
    './controllers/index',
    './directives/index',
    './filters/index',
    './services/index',
    './custom_module/index' // here we added index file

], function(angular) {

    console.log("creating app module");

    'use strict';

    return angular.module('app', [

        'ngRoute',
        'app.controllers',
        'app.services',
        'app.directives',
        'app.services',
        'custom_module' // here we added module dependency

    ]);
});

That's it!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.