AngularJS ng-bind-html无法在<ng-view>页面中使用

时间:2015-06-18 15:00:19

标签: angularjs

在母版页中,n-bind-html正在运行,但在调用视图页时,任何数据都没有。

ng-bind-html =“home.title”正在索引标题div中工作。

index.html

             ....

             <title ng-bind-html="home.title"></title>

             ....

            <ng-view></ng-view>

contact.html 但ng-view联系页面ng-bind-html =“home.title”无效,{{contact.info}}无效。

            <h4 ng-bind-html="home.title"></h4>
            <p>{{contact.info}}</p>

控制器:

    $scope.trustedHtml = function (plainText) {
        return $sce.trustAsHtml(plainText);
    }
    $http.get('admin/api/?s=getAbout&lang='+lang).success(
        function(r){
                $scope.about = r.text;
                //$scope.about = r.email;
        }
    );


    $http.get('admin/api/?s=getContact'+lang).success(
        function(r){
                $scope.contact = r;
                //$scope.contacttext.infoH = r[0].infoH;
                //$scope.contact.infoH = $sce.trustAsHtml(r.infoH); 

        }
    );


    $http.get('admin/api/?s=getHome&lang='+lang).success(
        function(r){
                $scope.home = r;
                $scope.home.address = $sce.trustAsHtml(r.address); 
                $scope.home.phone = $sce.trustAsHtml(r.phone); 
                $scope.home.email = $sce.trustAsHtml(r.email);
                $scope.home.title = $sce.trustAsHtml(r.title);                  
        }
    );
关于ng的ng-view页面正在运行。 about.html

       <div class="container" style="font-size:16px;" ng-bind-html="trustedHtml(about)"></div>

1 个答案:

答案 0 :(得分:0)

您需要为动态添加的元素添加以下代码。 See Here。希望这会有所帮助:

AngularApp.run(function($rootScope, $location, $timeout) {
    $rootScope.$on('$viewContentLoaded', function() {
        $timeout(function() {
            componentHandler.upgradeAllRegistered();
        });
    });
});

How Component Handle works

相关问题