Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section ng-app="myapp">
<div ui-view="viewA"></div>
    <div ui-view="viewB"></div>
    <!-- Also a way to navigate -->
    <a ui-sref="welcome">Welcome</a>
    <a ui-sref="app.dashboard">Application</a>  
  </section> 


<script type="text/ng-template" id="modallogindialogId">
<div>
                  <form ng-submit="LoginModalCtrl.submit(_email, _password)">
                    <input type="email" ng-model="_email" />
                    <input type="password" ng-model="_password" />
                    <button>Submit</button>
                  </form>
                  <button ng-click="LoginModalCtrl.cancel()">Cancel</button>
                </div>
  
</script>
              
            
!

CSS

              
                
              
            
!

JS

              
                var app = angular.module('myapp', ['ui.router', 'ngDialog']);
app.config(function ($stateProvider) {

  $stateProvider
    .state('welcome', {
      url: '/welcome',
      // ...
      data: {
        requireLogin: false
      },
    views: {
        "viewA": { template: "<p>Hello world from view a</p>" },
        "viewB": { template: "<p>Hello world from view b</p>" }
      }
    })
    .state('app', {
      abstract: true,
      // ...
      data: {
        requireLogin: true // this property will apply to all children of 'app'
      }
    
    })
    .state('app.dashboard', {
     url: '/app',
    views: {
            "viewA": { template: "<p>You already logged in. Hello world from view a</p>" },
            "viewB": { template: "<p>You already logged in.Hello world from view b</p>" }
      }
      // child state of `app`
      // requireLogin === true
    })

});
app.config(function ($httpProvider) {

  $httpProvider.interceptors.push(function ($timeout, $q, $injector) {
    var loginModal, $http, $state;

    // this trick must be done so that we don't receive
    // `Uncaught Error: [$injector:cdep] Circular dependency found`
    $timeout(function () {
      loginModal = $injector.get('loginModal');
      $http = $injector.get('$http');
      $state = $injector.get('$state');
    });

    return {
      responseError: function (rejection) {
        if (rejection.status !== 401) {
          return rejection;
        }

        var deferred = $q.defer();

        loginModal()
          .then(function () {
            deferred.resolve( $http(rejection.config) );
          })
          .catch(function () {
            $state.go('welcome');
            deferred.reject(rejection);
          });

        return deferred.promise;
      }
    };
  });

});
app.controller('LoginModalCtrl', function ($scope) {

  this.cancel = $scope.$dismiss;

  this.submit = function (email, password) {
    var user = {email: email, password: password};
     $rootScope.currentUser = user;
  };

});
app.service('loginModal', function (ngDialog, $rootScope) {

  function assignCurrentUser (user) {
    $rootScope.currentUser = user;
    return user;
  }

  return function() {
    var instance =   ngDialog.openConfirm({
    template: '<div>\
                  <form ng-submit="LoginModalCtrl.submit(_email, _password)">\
                    <input type="email" ng-model="_email" />\
                    <input type="password" ng-model="_password" />\
                    <button>Submit</button>\
                  </form>\
                  <button ng-click="LoginModalCtrl.cancel()">Cancel</button>\
                </div>',
      controller: 'LoginModalCtrl',
      controllerAs: 'LoginModalCtrl',
       plain: true
    });

    return instance.then(assignCurrentUser);
  };

});

app.run(function ($rootScope, $state, loginModal) {

  $rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
    var requireLogin = toState.data.requireLogin;

    if (requireLogin && typeof $rootScope.currentUser === 'undefined') {
      event.preventDefault();

      loginModal()
        .then(function () {
          return $state.go(toState.name, toParams);
        })
        .catch(function () {
          return $state.go('welcome');
        });
    }
  });
});

              
            
!
999px

Console