AngularJS, Angular-UI Router Hello World Starter App – Code Sample

This article represents code samples to get started with an AngularJS app with Angular UI-Router and Bootstrap. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.
Code Example – AngularJS 1, Angular UI-Router, Bootstrap

Pay attention to some of the following in the code given below:

  • Angular-UI router state information is used to associate links with templates
  • Angular-UI code with within tag element “ui-view” to load specific views
<!DOCTYPE html>
<head>
  <title>My AngularJS App</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body ng-app="myApp" class="container">
  <div class="page-header">
    <h1>Angular 1 - Angular UI Router</h1>
  </div>
  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-lg-2">
        <nav class="navbar navbar-default navbar-fixed-side">
          <ul class="nav nav-pills nav-stacked">
            <li role="presentation"><a ui-sref="about" ui-sref-active="active">UI Router App</a></li>
            <li role="presentation"><a ui-sref="hello" ui-sref-active="active">Say Hello</a></li>
          </ul>
        </nav>
      </div>
      <div class="col-sm-9 col-lg-10">
        <ui-view></ui-view>
      </div>
    </div>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
  <script src="//unpkg.com/angular-ui-router/release/angular-ui-router.min.js"></script>
  <script>
    angular.module('myApp', ['ui.router']).
    config(function($stateProvider) {
      $stateProvider
              .state({
                name: 'about',
                url: '/about',
                template: '<h3>Its the UI-Router hello world app!</h3>'
              })
              .state({
                name: 'hello',
                url: '/hello',
                template: '<h3>Hello world. How are you!</h3>'
              });
    });
  </script>
</body>
</html>

 

Hello World Screenshot

Following is how the above code would look like in a web page.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com

Share
Published by
Ajitesh Kumar

Recent Posts

Feature Engineering in Machine Learning: Python Examples

Last updated: 3rd May, 2024 Have you ever wondered why some machine learning models perform…

3 days ago

Feature Selection vs Feature Extraction: Machine Learning

Last updated: 2nd May, 2024 The success of machine learning models often depends on the…

4 days ago

Model Selection by Evaluating Bias & Variance: Example

When working on a machine learning project, one of the key challenges faced by data…

4 days ago

Bias-Variance Trade-off in Machine Learning: Examples

Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…

5 days ago

Mean Squared Error vs Cross Entropy Loss Function

Last updated: 1st May, 2024 As a data scientist, understanding the nuances of various cost…

5 days ago

Cross Entropy Loss Explained with Python Examples

Last updated: 1st May, 2024 In this post, you will learn the concepts related to…

5 days ago