Skip to content

Instantly share code, notes, and snippets.

@juanpablocs
Last active April 14, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpablocs/ed1dbdc8b616f1df73e1e6f42971fc63 to your computer and use it in GitHub Desktop.
Save juanpablocs/ed1dbdc8b616f1df73e1e6f42971fc63 to your computer and use it in GitHub Desktop.
angular with ecmac script 6

usar alguna herramienta para tratar modulos ejemplo : (webpack, browserify)

ejemplo básico

js:

// import angular
import angular from 'angular';
// init angular
angular.module('myApp',[]);
// set controller
angular.controller('HomeController', ()=> {
  this.hello = 'hello';
});

html:

<body ng-app="myApp">
 <div id="home" ng-controller="HomeController as home">
  <p> say: {{ home.hello }}</p>
 </div>
</body>

ejemplo usando imports y class

App.js:

import angular from 'angular';
import HomeController from './HomeController'; //no es obligatorio .js

angular.module('myApp',[]);
angular.controller('HomeController', HomeController);

HomeController.js:

class HomeController{
  constructor(){
    this.hello = 'Hello Wold';
  }
}
export default HomeController;

html:

<body ng-app="myApp">
 <div id="home" ng-controller="HomeController as home">
  <p> say: {{ home.hello }}</p>
 </div>
</body>

ejemplo usando ngNewRouter

App.js:

import angular from 'angular';
import router from 'angular-new-router';

import './components/home/home'; //no es obligatorio .js

angular
  .module('myApp',[
    'ngNewRouter',
    'myApp.home'
  ])
  .controller('AppController', ['$router', ($router)=>{
    // set routing
    $router.config([
      { path: '/', redirectTo: '/home' },
      { path: '/home', component: 'home' }
    ]);
  
  }]);

components/home/home.js

import angular from 'angular';
import HomeController from './HomeController';

(function(){
	'use strict';
	angular.module('myApp.home',[])
		.controller('HomeController', HomeController)
})();

component/home/HomeController.js:

class HomeController {
  constructor(){
    this.hello = 'Hello World';
  }
}
export default HomeController;

component/home/home.html

<p> {{home.hello}} </p>

index.html

<body ng-app="myApp" ng-controller="AppController">
  <h1>Welcome to future</h1>
  <div ng-viewport class="container-fluid"></div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment