添加& lt; object>使用AngularJS控制器自定义属性

Add <object> with custom attributes using AngularJS controller

本文关键字:控制器 AngularJS 自定义属性 使用 object lt 添加      更新时间:2023-09-26

我试图使用控制器将<object></object>添加到我的html中。当我加载<div><p>时,它工作正常,但当我添加<object>时,它不出现,也没有任何自定义属性。

HTML:

<html ng-app="myAngularSite">        
...
...
    <div ng-controller="MyController">
        <div id="myloader" ng-bind-html="myObject"></div>
    </div>

JS:

var app = angular.module('myAngularSite', ['ngRoute']);
angular.module('myAngularSite', ['ngSanitize'])
        .controller('MyController', ['$scope',function($scope) {
            $scope.myObject = 
                '<object id="my_object" data="mysite.html" width="99.5%" height="400px" style="overflow:auto;border:3px ridge gray"/>';
        }]);

如何将自定义属性和对象添加到我的站点中?我注意到,当我尝试加载带有属性的<div id"with_attribut></div>时,属性不会出现,尽管div会自己出现。

谢谢!

自定义指令可能是很好的解决方案,您可以随时添加更多自定义行为。使用ngBindHtml,您将受到限制。这是一个可以帮助你的链接:

angular ng-bind-html和其中的指令