使用AngularJS删除DOM元素
发布时间:2020-12-17 17:42:19 所属栏目:安全 来源:网络整理
导读:我正在尝试根据当前位置路径删除导航栏. 这是我到目前为止: angular.module('myModule') .controller('MainController',function ($location,$document) { if ($location.path().indexOf('resetpass') -1) { var navbar = angular.element($document.queryS
我正在尝试根据当前位置路径删除导航栏.
这是我到目前为止: angular.module('myModule') .controller('MainController',function ($location,$document) { if ($location.path().indexOf('resetpass') > -1) { var navbar = angular.element($document.querySelector(".top-navbar")); navbar.remove(); } }); 通过这种方法,控制台说: angular.js:14110 TypeError: $document.querySelector is not a function at new <anonymous> (main.controller.js:6) at Object.invoke (angular.js:4762) at $controllerInit (angular.js:10518) at nodeLinkFn (angular.js:9416) at compositeLinkFn (angular.js:8757) at compositeLinkFn (angular.js:8760) at publicLinkFn (angular.js:8637) at angular.js:1808 at Scope.$eval (angular.js:17913) at Scope.$apply (angular.js:18013) 我究竟做错了什么? 解决方法
在你的DOM元素中使用ngIf,并执行以下操作:
模板: <element ng-if="hideElemet"></element> 控制器: if ($location.path().indexOf('resetpass') > -1) { $scope.hideElement = false } ngIf将从DOM中删除该元素 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |