Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng bind html添加了css类';ng绑定&x27;这会破坏所有嵌套的css,如何摆脱它?_Javascript_Css_Angularjs_Angular Ui Bootstrap_Ng Bind Html - Fatal编程技术网

Javascript ng bind html添加了css类';ng绑定&x27;这会破坏所有嵌套的css,如何摆脱它?

Javascript ng bind html添加了css类';ng绑定&x27;这会破坏所有嵌套的css,如何摆脱它?,javascript,css,angularjs,angular-ui-bootstrap,ng-bind-html,Javascript,Css,Angularjs,Angular Ui Bootstrap,Ng Bind Html,我想从$scope变量添加一些html来查看。我想把它添加到angular ui导航栏中。当我在浏览器中检查生成的代码时,它是绝对正确的,但似乎附加的css样式会破坏一切 我的html看起来像: ... navbar headers <ul class="nav navbar-nav" ng-bind-html="menuHTML"></ul> 呈现的页面看起来和预期的一样,但下拉菜单不起作用当我从浏览器复制不工作的html并手动打印它时,不使用ng bind html

我想从
$scope
变量添加一些html来查看。我想把它添加到angular ui导航栏中。当我在浏览器中检查生成的代码时,它是绝对正确的,但似乎附加的css样式会破坏一切

我的html看起来像:

... navbar headers
<ul class="nav navbar-nav" ng-bind-html="menuHTML"></ul>
呈现的页面看起来和预期的一样,但下拉菜单不起作用当我从浏览器复制不工作的html并手动打印它时,不使用
ng bind html
并删除
ng binding
样式,一切正常

如何强制绑定html只添加html而不添加一些额外的css?另一种方法是创建自己的指令,但复制粘贴的代码不起作用。可能问题的作者没有展示所有内容,因此我没有包括一些重要的模块,遗漏了分号,做出了错误的控制器指令声明顺序(?)e.t.c


有谁能告诉我,如何使用ng bind html而不使用其恼人的额外css或提供正确的指令示例吗?

好的,问题是插入的html包含角度特定的元素,因此我必须创建特殊指令,在插入后编译html。关于这些答案

var myApp = angular.module('myApp', ['ui.bootstrap','ngSanitize']);



myApp.controller('NavBarCtrl', function($scope, $http, $window,$sce) {

    $scope.isCollapsed = true;

    $scope.changeLanguage = function (language){
        console.log(language);
        var url = $window.location.href;
        if (url.indexOf('?') > -1){
            url = url.substr(0,url.indexOf("?"));
            url += '?language='+language;
        }else{
            url += '?language='+language;
        }
        $window.location.replace(url);
    };

    $http.get('headerMenu').success(function(res){
        console.log('header ok');
        $scope.headerMenuHTML =  $sce.trustAsHtml(res);
    });


});