html - 基于 URL 参数的 Angular 显示 div

标签 html angularjs if-statement

在 Angular 中,有没有一种方法可以根据存在的 URL 参数显示内容?

例如,myfile.php?id=123

<div ng-if="window.location.search.id != ''">
    Show content
</div>

最佳答案

在你的 Controller /指令中你可以注入(inject) $location并用它来检查查询参数

 angular
    .module('locationExample', [])
    .controller('ExampleController', 
     ['$scope', '$location', function($scope, $location) {
         $scope.search = $location.search();
     }]);


<div ng-if="$scope.search.id != ''">
    Show content
</div>

关于html - 基于 URL 参数的 Angular 显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31680695/

相关文章:

html - 我可以将 div 放入选取框元素中吗

javascript - AngularJS - 获取标题作为响应

java - android 夹板字符串

java - IF 条件满足但跳到下一个 IF

php - 如何分离sql查询的结果?

html - CSS:在浏览器调整大小时将文本居中放置在 d3 slider 下

javascript - HTML数据属性IE6支持

javascript - 我们如何设计来自数组连接的字符串?

javascript - Protractor :按属性查找元素

c++ - 相对于其数据朝特定方向移动的有效方法是什么?