0

I have a website setup with 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>

-When any of those ui-sref clicked I want to hide or display:none to that div class with wanTohide. Of course ui-sref clicked it has load its content to ui-view.

-I want to functional Home Page button.<a href="">Home Page</a>

1 Answer 1

0

You can $stateChangeStart to achieve this. Basically, $stateChangeStart is fired whenever a state changes. Code:

app.js(where your app is defined) :

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 == 'oku'|| fromState.name == 'icerik') {
            angular.element('.wantToHide').addClass('hidden');
        }
    }) 
}

CSS:

.hidden {
    display: none;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.