url上存在Angularjs检查或单词

url上存在Angularjs检查或单词,angularjs,Angularjs,我的目标是在angularjs控制器上实现,如果url带有#howhtttp://www.example.com#how如果url没有#howhtttp://www.example.com webApp.controller('ctrl',function($scope){ $scope.showHow = ???; // if url with #how == true else false ... 我用这样的东西 webApp.controller('ctrl',function($sc

我的目标是在angularjs控制器上实现,如果url带有#how
htttp://www.example.com#how
如果url没有#how
htttp://www.example.com

webApp.controller('ctrl',function($scope){

$scope.showHow = ???; // if url with #how == true else false
...

我用这样的东西

webApp.controller('ctrl',function($scope) {
    $scope.showHow = window.location.hash.indexOf('how') > 0
}

您可以使用$location服务

webApp.controller('ctrl',function($scope, $location){

$scope.showHow = $location.hash() === 'how'; // if url with #how == true else false
详见


但一般来说,如果应用程序在url更改时显示一些内容,最好的选择是使用or。

通常最好使用Angular的
$window
服务