0
     <select class="form-control"
     ng-if="((!$state.includes('home.allprojects') ||
     !$state.includes('home.Sentprojects')) &&
     !dynamicFields.isShowVismaButtons)" 
     ng-model="projects.selectedBokYear" ng-change="onBokYearChange()"
     ng-options="font.value for font in projects.bokYears"></select>

Here the code must display if the state is not in the home.allprojects or home.Sentprojects and !dynamicFields.isShowVismaButtons

ng-if="((!$state.includes('home.allprojects') || !$state.includes('home.Sentprojects')) && !dynamicFields.isShowVismaButtons)"

but the Select is visible even in the home.allprojects and home.Sentprojects state

can any one give a solution for it

  • I would suggest putting this whole `ng-if` code inside a function in your model – Derlin Apr 09 '18 at 10:32
  • 1
    you cant access $state inside html – Sravan Apr 09 '18 at 10:32
  • 1
    You can't access $state directly in HTML. Use any scope variable to store $state and try to access it from that variable. – Srigar Apr 09 '18 at 10:32
  • https://stackoverflow.com/questions/22748456/angular-js-ng-show-element-when-state-current-name-is-a-certain-value – Santosh Singh Apr 09 '18 at 10:39
  • Use this link might be there is condition issue also debug your value by putting inside {{ ((!$state.includes('home.allprojects') || !$state.includes('home.Sentprojects')) && !dynamicFields.isShowVismaButtons) }} in html – Santosh Singh Apr 09 '18 at 10:41

1 Answers1

0

You cant access $state in html,

Instead write a function which defines your logic and call that function from your HTML, or you can take a variable and use it in html for state

I prefer going with a function which I added in my answer.

HTML:

<select class="form-control"
ng-if="checkState()"
ng-model="projects.selectedBokYear" ng-change="onBokYearChange()"
ng-options="font.value for font in projects.bokYears"></select>

In controller,

$scope.checkState = function(){
    return ($state.includes('home.allprojects')) ||
           (!$state.includes('home.Sentprojects')) &&
           (!$scope.dynamicFields.isShowVismaButtons)
}

I have created a checkState function from HTML and defined your logic there.

Also, to check the state directly if there is no parent-child, you can use $state.current.name

$scope.checkState = function(){
return ($state.current.name != 'home.allprojects') ||
       ($state.current.name != 'home.Sentprojects') &&
       (!$scope.dynamicFields.isShowVismaButtons)
}
Sravan
  • 18,467
  • 3
  • 30
  • 54