1

I am new at JavaScript and AngularJS. I catch a problem. I want to remove h1 tag when go to /main route. I know that i must use ng-if and expression with $location at controller.

<html>
<body>
...
<h1 ng-if "? ">
    sometext
</h1>
<div ng-view></div>
</body>
...
</html>

What expression i must use to remove this , or i must write function at controller to check.Thank you in advance

4

1 回答 1

1

您可以编写一个函数ng-if来检查应用程序的当前 URL / 状态,并根据条件结果返回真/假

<h1 ng-if="toShowHeader()">MY HEADER</h1>

$scope.toShowHeader = function(){
   return $location.path() === '/login';
   //return $state.current.name === 'login'; //if you have ui-router in place.
};
于 2016-07-24T17:38:20.153 回答