Unique styles and scripts for a custom login portal

Just beginning with angularjs and diving into a project. Using ui.router for handling various views. Encountering an issue where I have a main page index.html, all my views load in

<div ui-view=""></div>
. But what if I want to incorporate a login page with different styles and scripts? Example:

<html lang="en" ng-app="leadsangularApp">
<head>
    <link href="style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div ui-view=""></div>
</body>
</html>

If trying to achieve this with nested ui-views:

 app.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/home');
          // States
          $stateProvider
            .state('root', {
                abstract: true,
                templateUrl: 'views/default.html',
            })
            .state('home', {
                parent: "root",
                url: "/home",
                templateUrl: 'views/main.html',
            })
            .state('login', { 
                url: "/login",
                templateUrl: 'views/login.html',
            });
  });

Even though the /login page has a different view, it is still loading the same css and js files. How can I set up the /login page to have a completely different head section and footer section?

Answer №2

If you want to utilize ng-href, you will need to pay attention to $stateChangeSuccess and modify the values bound to ng-href based on your requirements.

Here is an example of how to implement it in your HTML:

<link rel="stylesheet" ng-href="{{styleFile}}" />

The variable styleFile should be dynamically linked to your scope and can be updated as needed.

You can then monitor either $stateChangeStart or $stateChangeSuccess events and adjust the value of $scope.styleFile accordingly.

app.controller('mainCtrl', function($scope, $state) {
  $scope.styleFile = "style.css";

  $scope.$on('$stateChangeStart',
    function(event, toState, toParams, fromState, fromParams) {

      if (toState.name === "login") {
        $scope.styleFile = "style2.css"
      } else {
        $scope.styleFile = "style.css"
      }
    })
})

Check out the Plunker demo here: http://plnkr.co/edit/qR7FLDAyRTkFndMQyWod?p=preview

For more information on ui-router's API, visit: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state

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

Is there a way to include @odataid in an ajax request in order to invoke a post method that assigns an owner to a group?

Seeking assistance on how to utilize ajax for adding an Owner to an O365 group. Utilizing the following endpoint: https://graph.microsoft.com/v1.0/groups/{id}/owners/$ref This is my current ajax call setup, where I am passing user information through the ...

After sending a post request, the form in HTML with Node.js is returning an undefined response

Upon creating an HTML <form></form> object to capture a username, email, and password, I encountered an issue where the value returned is always undefined when accessing req.body.name or any other field. It seems like the form is not functionin ...

Is there a way to make a trio of buttons arranged in a flex column slide out to the left when hovered over using flexbox?

access the code example here .container { display: flex; flex-direction: column; border: 2px solid blue; } .mainCont { display: flex; background-color: #f2f2f2; min-height: 5em; justify-content: space-between; } .btn-group { display: f ...

Transferring HTML variables to CSS

I've been searching for an answer without much luck. Is it possible to transfer variables from HTML to CSS, maybe using data attributes? I want to display different backgrounds based on vendors using media queries on brand pages. I know inline CSS d ...

Flex just can't seem to align correctly

I'm having trouble getting this to work properly. I am using React and styled components, but the justify/content alignment is not functioning as expected. The setup includes a div with flex properties, where the flex direction is set to column. With ...

Exploring how to use mongoose queries within express routes

Having issues testing my routes with mongoose queries. I keep receiving this error: AssertionError: expected undefined to equal true Below is the structure of my test. Right now, I just want to verify that it calls res.json. The route retrieves all reco ...

Saving data from rowclicked event in ag-grid with Angular

My goal is to save the event data from the onRowClicked event in a Component member. This way, when the user clicks a button, the data can be deleted. However, I am facing an issue where the member variable becomes undefined when trying to access it in t ...

Toggling the visibility of divs in a dynamic layout

How can I use JQuery/JavaScript to show only the comment form for a specific post when a button or link is clicked on a page containing multiple posts divs with hidden comment forms? <div class="post"> <p>Some Content</p> <a ...

Transitioning Vue components dynamically

I am facing an issue where the Vue transition is not working as expected for my dynamic components. Check out my code snippet below: <template> <div> <component :is="currentView" transition="fade" transition-mode="out-in">< ...

Balanced-JS encounters a 404 error

I am currently testing out the code sample provided in the following link: https://github.com/balanced/balanced-js After following the README instructions, I was able to get my local server up and running. However, when I visit the website and try to tok ...

The variants array in VUE.js is not displaying properly

I have recently been delving into vue.js for my work and encountered a significant issue. I wanted to create a simple TODO application. In my index.html file, I only have a div for a header and a root div with an ID: #app. Inside the root div, there is a ...

Error in Angular2: Unresolved Variables

Hello world, seeking guidance, I recently started learning Angular2 and ventured into creating a simple app which is now not working! The component.ts file import {Component, OnInit} from '@angular/core'; import { Player } from './player.m ...

Fire an event following the execution of $state.go()

Is there a way to activate an event once the state has been modified in ui.router? Specifically, I am utilizing the ionic framework alongside angularJS which incorporates angular-ui-router. Note: Below is the pseudo code I am hoping to implement. $state. ...

Max value determined by a variable within a for loop

UPDATE: Revised code provided. In my Node.js JavaScript project, I am creating a script to iterate through a dataset obtained by web scraping. The main goal of this algorithm is: 1) Examine the player table for the presence of the player's name in a ...

How come pagination links in Vue.js 2 return JSON when clicked?

My question relates to having 2 specific components: Firstly, there is a component called SearchResultVue.vue. The structure of this component is as follows : <template> ... <span class="pull-right" v-show="totalall>8"> ...

Unable to fetch data from Django Template (.html) in my views

I'm a beginner in the world of Django and I'm currently working on a project that involves managing learning objects metadata. One of the essential functions of the system is to display the L.O. metadata directly in the web browser. Within my HT ...

What is preventing BODY from respecting min-height: 100% ?

Struggling to create a basic webpage with a container that extends to the bottom? Here's what I'm aiming for: #Main should be as tall as the viewport, but able to stretch further with additional content. body should match the viewport height, y ...

I keep trying to retrieve a specific property from an object, but every time I do, it returns as undefined

I'm currently employing Javascript within a React component. My goal is to retrieve a specific property from an object. If I log this object out to the console as shown below: console.log("Engine: ", this.Engine); The output looks like th ...

Error: Exceeded the hook limit during rendering - reactjs problem

I keep encountering an issue when trying to retrieve main data using useSwr, where I call another function with axios and end up with an Uncaught Error: Rendered more hooks than during the previous render. I've attempted to troubleshoot this countless ...

Steer clear of using grey backgrounds for anchors/links in IE 10

What is the best way to prevent the irritating grey background that appears on anchors in IE 10 when they are clicked? ...