Updating a portion of HTML using ES6 syntax in conjunction with the angular-webpack-seed framework

This angular version is unfamiliar to me, and I'm struggling to find a good example to follow. Can you provide some assistance?

https://i.sstatic.net/CJ6XC.png

I am looking to update the right section of this page without refreshing it using ES2015 + AngularJS + Webpack framework.

Currently, the page has a controller named 'home'. When the user clicks on the left side, I want to update the right section with a separate controller.

I know I can use ng-controller = ..., but transitioning to ES2015 and Webpack has left me confused.

Here's what I have so far.

Firstly, the index.html

<html ng-app="abc" ng-strict-di>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
    <title>{%= o.htmlWebpackPlugin.options.title %}</title>
  </head>
  <body>
    <div class="container" ui-view></div>
  </body>
</html>

Next, the router.js

import HomeController from './home';

export default function routes($stateProvider) {
  'ngInject';
  $stateProvider
    .state('home', {
      url: '/',
      template: require('./home.html'),
      controller: HomeController,
      controllerAs: 'home',
    })
    .state('android', {
      url: '/android',
      template: '<h2>This is Android</h2>',
      parent: 'home'
    });
}'

One question I have is, the syntax

'export default function routers($stateProvider) {}'
is different than what I'm used to in Angular. Could someone clarify this for me?

This is how I've defined my HomeController, I aim to adhere to standard practices by creating separate controllers for different sections of the page.

export default class HomeController {
constructor($http) {
    'ngInject';
    this.currentPlatform = '';
    this.platforms = [
      {
        displayName: "WEB PORTAL",
        value : "WEB PORTAL"
      },
      {
        displayName: "ROKU",
        value : "ROKU"
      },
      {
        displayName: "Android",
        value : "ANDROID"
      },
      {
        displayName: "iPhone",
        value : "iPhone"
      }
    ];
    this.$http = $http;
    this.projectName = "";
    this.appId = "";
    this.version = "";
    this.fieldData = "";

  }
}

Additionally, here is the home.html markup for reference.

<div class="home">
  <div class="title">
    <h1 class="h3">Build/Configure Apps</h1>
    <span class="glyphicon glyphicon-remove"></span>
  </div>
  <div class="main">
    <div class="row">
      <div class="col-sm-4">
        <ul class="nav nav-pills nav-stacked">
          <li role="presentation" ng-repeat="platform in home.platforms" ng-class="{active: home.isSelected(platform.value)}">
            <a ng-click="home.setPlatform(platform.value)">{{platform.displayName}}</a>
          </li>
        </ul>
        <div class="form-inline form-group">
          <div class="form-group">
            <label for="appId" class="control-label">App Id:</label>
            <input type="text" name="appId" ng-model="home.appId" class="form-control">
          </div>
        </div>
        <div class="form-group">
          <button type="button" name="button" class="btn btn-sm btn-primary col-sm-8" ng-click="home.makeAjaxCall()">Submit</button>
        </div>
      </div>
      <div class="col-sm-8">
        <h2>The right content should dynamically update when clicking on the left navigation, while the left side remains static.</h2>
      </div>
    </div>
  </div>
</div>

Thank you in advance for your help!

Answer №1

Your query seems a bit broad, but I have the necessary background to provide you with a detailed response.

Let's address your initial question:

export default function routers($stateProvider) {}

This code snippet indicates the use of ES6 in conjunction with angular-ui-router - where UI-Router specific routes are utilized for defining states.

To implement your design, modifications must be made to static/index.html. It should look something like this:

 <body>
    <div class="container">
       <div ui-view="navbar">
       </div>
       <div ui-view></div>
    </div>
  </body>

Next, create a navbar view within the stateprovider that points to navbar.html which includes:

<ul class="nav nav-pills nav-stacked">
   <li role="presentation" ng-repeat="platform in home.platforms" ng-class="{active: home.isSelected(platform.value)}">
    <a ng-click="home.setPlatform(platform.value)">{{platform.displayName}}</a>
  </li>
</ul>

`

 $stateProvider
    .state('navbar', {
      template: require('./navbar.html'),
      controller: NavbarController,
      controllerAs: 'navbar',
    })

You can start with these steps to move forward on your project.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Concatenation in JavaScript replaces only the first character of a string

Objective My current task involves extracting SQL statements from a log file and performing simple string concatenation to add a semicolon (;) at the end: var query = line[i] + ";" Issue Expected output: insert into [...]; Actual output: ;nsert into ...

Steps for integrating csurf into Node.js and React.js

I have been struggling to implement csurf in my react js application on node js. Can someone guide me on the correct way to implement it? Project Directory -admin -client -config -middleware ----file.js ----variables.js -models -node-modules -routes -util ...

EdgeDriver with Selenium and Java can be interrupted by a modal window dialog box, causing the test script to pause its execution

I am in the process of creating a test script for our web application to test the upload functionality of a profile picture using Microsoft Edge and EdgeDriver. However, I am facing an issue where the script stops running completely after initiating the cl ...

Converting a ref or div to an Excel format using JavaScript or jQuery

I am facing an issue with exporting multiple tables to Excel in a React project. The main problem is that when I try to export the tables using libraries like "react-html-table-to-excel-3", only the first table gets exported and not the nested table insi ...

Performance.now() and its interaction with the toFixed() method

When you apply toFixed to performance.now, it displays a specific number of digits that may not be rounded as expected. Interestingly, the number of digits can vary based on the platform used. For instance, in Chrome (v87.0.4280.66), it can show up to 35 ...

Navigational issues while incorporating path.join with __dirname in node.js

Can you clarify the distinction between using path.join(__dirname, "src/js") and simply __dirname + "src/js") in a node.js environment? ...

Navigating React Redux Pages Using React Router

At the moment, I am exploring the possibility of creating an application using React and Redux. Most examples I've come across make use of React Router, so I'm curious about its purpose. My application will consist of multiple pages (at least 20 ...

Why does jQuery utilize the anonymous function wrapper?

When delving into jQuery's code structure, one notices that it begins by enveloping all of its code within an anonymous function: (function ( window, undefined) { /* ...jquery code... */ }) (window); It is clear that this function is immedi ...

The data type 'string' cannot be assigned to type [object]

Here's a scenario using an interface: interface Order { symbol: string side: string price: number quantity: number } In my code, I have a section where I am trying to access values within a table. However, it's giving me an error saying tha ...

When adding classes using Angular's ng-class, CSS3 transitions are not activated

After creating a custom modal directive in Angular, I am encountering an issue with the transition animation not working as expected. Within my directive's isolated scope, there is a method called toggleModal() that toggles the modalState between true ...

The Selenium server is currently operational, however, it is encountering issues while attempting to establish a connection with the

I am currently working on setting up test automation using WebdriverIO. After successfully installing all the necessary packages with selenium-standalone, I encountered an issue when trying to start the server. https://i.sstatic.net/7K1O5.png Upon runnin ...

Having trouble with webpack while attempting to build a React application

I have been following a tutorial on how to set up a React app at https://www.tutorialspoint.com/reactjs/reactjs_environment_setup.htm, but I am encountering some difficulties while trying to run the app. Below is the error message I receive when I enter n ...

Generate dynamic DIV elements and populate them with content

Can you assist me in getting this code to function properly? My goal is to dynamically create elements inside a div and fill each element with a value fetched from the database through a server-side function. I'm unsure if there's a better approa ...

What is the process of integrating unique themes into a non-Wordpress website?

In the process of developing my website, I am using PHP7, HTML5, CSS3, JQuery, and JavaScript5 instead of WordPress. One feature that I want to incorporate is the ability for users to customize their theme beyond the default option. How can this be achie ...

Encountered an issue while attempting to deploy my app on Heroku: received the error message "The requested resource does not have the 'Access-Control-Allow-Origin' header"

Hi fellow developers, I'm currently facing an issue while trying to upload a simple app to my Herokuapp. Every time I attempt to log in or sign up and establish a connection with the back-end, I encounter the following CORS error: "Access to fetch at ...

I'm experiencing an issue with the sub-menu disappearing and preventing me from clicking on any links

Currently, I have set up a navigation bar with a sub-menu that spans the full width of the page. When hovering over the list items, the sub-menu appears as expected. However, when moving the mouse down into the sub-menu, it disappears instantly. The object ...

AngularJS Project Guide for Running Breeze Queries

I need assistance creating a universal function to run a breeze query. This function must fulfill the following objectives: Check if the query has been executed before, and if so, run the query locally. Be compatible with environments like Sharepoint 201 ...

Merge and combine two JSON files

My dilemma involves two JSON files: F1_data.json: { "A": { "time": "2015-11-26T08:20:15.130Z", }, "B": { "time": "2015-11-26T08:30:19.432Z", { "C": { "time": "2015-11-26T08:20:15.130Z", } } F2_data.js ...

Attempting to send a filled array to res.render, but struggling to implement a suitable async callback mechanism

I am facing a challenge in creating a function that retrieves a list of IPs from a database, collects server information based on those IPs, stores the data in objects, and finally adds these objects to an array. While I can successfully populate each obje ...

attempting to sidestep the need to convert object into a string value

Let me explain the process: I am receiving various objects from an AJAX request ($scope.products - $scope.offers) and then using ng-repeat to display them, allowing the user to select multiple items (stored in $orderForm.products and $orderForm.offers). ...