Nested UI routing with hidden display

I am working on a website using AngularJS and Ui-router.

Index.html

<body>   

    <a href="#">Home Page</a>

<div ui-view></div>

</body>

Javascript:

.config(function($stateProvider, $urlRouterProvider) {

$stateProvider
.state('baba', {
url:"/",
templateUrl: "baba.html"
})
.state('icerik', {
url: "/icerik/:ad",
templateUrl: "icerik.html",
controller: "mmgCtrl",
 })

.state('oku', {
url: "/oku/:serix/:klasor",
templateUrl: "oku.html",
controller: "nbgCtrl"
})

$urlRouterProvider.otherwise('/');

})

baba.html:

<div class="wanTohide> //div that want to hide when ui-sref clicked

    <a ui-sref="oku">State oku</a>
    <a ui-sref="icerik">State icerik</a>

</div>

-If any of the ui-sref links are clicked, I want to hide or apply display:none to the div with the class wanTohide. The content should load in the ui-view.

-I also want the Home Page button to be functional.

<a href="">Home Page</a>

Answer №1

To achieve this, you can use the $stateChangeStart function. Essentially, $stateChangeStart is triggered every time a state changes within your application. Here's the code snippet:

main.js(where your main script is located) :

app.run(run) //assuming app is a variable assigned 'angular.module('AppName', [])'

function run($rootScope, $state) {
    $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
        if(fromState.name == 'read'|| fromState.name == 'content') {
            angular.element('.wantToHide').addClass('hidden');
        }
    }) 
}

CSS:

.hidden {
    display: none;
}

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

Python script for extracting content from web pages that are loaded dynamically

I am facing an issue with extracting content from a webpage on my website. Despite trying to use selenium and clicking buttons, I have not been successful. #!/usr/bin/env python from contextlib import closing from selenium.webdriver import Firefox import ...

Error: The system encountered an issue while trying to access an undefined property 'find'

I've been working on developing the backend for a wishlist feature, but I've encountered an issue with my code. (node:19677) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'find' of undefined Despite trying to redefi ...

Error: The EJS compiler encountered a SyntaxError due to an unexpected token || in the show component file located at /var/www/html

I'm currently working on a project inspired by Colt Steele's YelpCamp creation during his Udemy Web Dev Bootcamp. Everything was going smoothly until I tried to refactor some code towards the end of the course using YouTube tutorials. Now, whenev ...

Leveraging the power of jQuery to capture and recycle a dynamically generated date

Using a jQuery plugin, a list of dates is generated. Implementing moment.js works perfectly fine as shown in this fiddle (http://jsfiddle.net/UJ9z4/). However, when attempting to apply it to the live file with the plugin running, an undefined error is enc ...

encountering a problem while trying to run `npm install react-native-modal-datetime-picker` in the terminal

I've encountered an issue while working on my app where I keep getting errors when trying to install the react-native-modal-datetime-picker package, as well as other date time picker packages like @react-native-community/datetime-picker The specific ...

Transforming a flow type React component into JSX - React protocol

I have been searching for a tooltip component that is accessible in React and stumbled upon React Tooltip. It is originally written in flow, but I am using jsx in my project. I am trying to convert the syntax to jsx, but I'm facing difficulties with t ...

The picture was not uploaded via Cordova's Android file transfer

I've set up a page that allows users to either take a photo or choose one from their phone's gallery, and it's functioning as expected. However, I'm looking to now upload the selected photo to my server on my Godaddy hosting. To achieve ...

retrieve room from a socket on socket.io

Is there a way to retrieve the rooms associated with a socket in socket.io version 1.4? I attempted to use this.socket.adapter.rooms, but encountered an error in the chrome console: Cannot read property 'rooms' of undefined Here is the method I ...

jQuery Plugin - iDisplayLength Feature

I am currently using DataTables version 1.10.10 and I am looking to customize the main plugin Javascript in order to change the iDisplayLength value to -1. This adjustment will result in displaying "All" by default on all data tables, allowing users to fil ...

The command is not currently carrying out its function

I am attempting to verify whether the "sender" has either of the two specified roles, but for some reason the command is not being executed. There are no errors showing up in the console, it's just that the command doesn't run. const revAmount = ...

Utilize a callback function without any arguments, and make use of the

After working on tutorials from nodeschool.io, I encountered a challenging problem related to streams. The provided solution had me puzzled. I'm particularly confused about the role of the upper variable and why it's necessary to use this.push. ...

Phonegap - Retaining text data in a checklist app beyond app shutdown

This is my first time developing an app with Phonegap. I am looking to create a checklist feature where users can input items into an input field. However, I am struggling with figuring out how to save these items so that they remain in the checklist even ...

Storing client-requested data locally

Is it possible to use JavaScript to make an AJAX request to fetch data from a server, then prompt the user to save this data on their computer for later access outside of the browser session? Can this saving functionality be achieved without using a Flas ...

Pressing the non-responsive button automatically chooses the following item

This example demonstrates how to create a disabled button: import { Grid, IconButton } from "@material-ui/core"; import ArrowBackIosIcon from "@material-ui/icons/ArrowBackIos"; export default function App() { const handleClick = (e) ...

Incorporate user input into Alert Dialog Boxes

Would you be able to assist me in displaying the input value from the "email" field in my alert box? The code seems to be working fine, but I'm having trouble getting the alert box to show the email form value. I decided to use Bootstrap for som ...

Is there a way I can obtain the code for a message box?

When I refer to a message box, I am talking about a container that gives users the ability to input their text and access different features like BOLD, ITALIC, color, justify, etc., in order to customize their message's appearance! (Think of it as the ...

What is the best way to showcase the output of a Perl script on a webpage

I recently came across a resource discussing the process of executing a perl script from a webpage. What is the best way to run a perl script from a webpage? However, I am facing a situation where the script I have takes more than 30 seconds to run and d ...

Succession of Mongoose queries

One interesting feature of my model is the ability to chain queries like find(), limit(), and skip(). However, there arises a question: How can I apply the limit or skip function to the output of Model.find() if the returning value does not inherently cont ...

Using ASP.NET MVC to map FormData with an array to a model class

I am currently facing an issue with mapping a list of objects in a FormData to my ASP.NET MVC Model class at the controller. I have successfully sent the FormData over to the server-side, but I am unable to bind any value. Can someone provide guidance on h ...

Using Typescript to define classes without a constructor function

As I was going through the "Tour of Heroes" guide on the Angular website, I came across the following code snippet: class Hero { id: number, name: string, } const aHero: Hero = { id: 1, name: 'Superman' } console.log(aHero instanceof H ...