JSFiddle - React, Tailwind, and code Playground

by lottikarotti

HTML

<script src="https://code.angularjs.org/1.5.0/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
<div ng-app='app'>
  <!-- main-view -->
  <div ui-view></div>
  
  <!-- inline templates -->
  <script type='text/ng-template' id='templates/app.html'>
  	<div>
      <h1>App</h1>
      <p>Current state: {{ vm.state.current.name }} ("{{ vm.getPath() }}")</p>
      <div ui-view></div>
		</div>
  </script>
  <script type='text/ng-template' id='templates/index.html'>
  	<div>
      <h2>Index</h2>
      <a href ng-click='vm.goToContact();'>go to contact</a>
		</div>
  </script>
  <script type='text/ng-template' id='templates/contact.html'>
  	<div>
      <h2>Contact</h2>
      <a href ng-click='vm.goToIndex();'>back to index</a>
		</div>
  </script>
</div>

CSS

html, body{
  font-family: arial, sans-serif;
}

JavaScript

angular.module('app', ['ui.router'])

.config(function($urlRouterProvider, $stateProvider){
	$urlRouterProvider.otherwise('/');
	$stateProvider
  	.state('app', {
      template: '<app></app>'
    })
  	.state('app.index', {
    	url: '/',
      template: '<index></index>'
    })
  	.state('app.contact', {
    	url: '/contact',
      template: '<contact></contact>'
    });
})

.component('app', {
  templateUrl: 'templates/app.html',
  controller: function($scope, $state, $location){
  	var vm = $scope.vm = {
    	state: $state,
      getPath: function(){
      	return $location.path();
      }
    };
  	console.info('app.controller executed');
    // ..
  }
})

.component('index', {
	templateUrl: 'templates/index.html',
  controller: function($scope, $state){
  	var vm = $scope.vm = {
    	goToContact: function(){
      	$state.go('app.contact');
      }
    };
  	console.info('index.controller executed');
  	// ..
  }
})

.component('contact', {
	templateUrl: 'templates/contact.html',
  controller: function($scope, $state){
  	var vm = $scope.vm = {
    	goToIndex: function(){
      	$state.go('app.index');
      }
    };
  	console.info('contact.controller executed');
    // ..
  }
});