Javascript 角度指令(不作为HTML呈现)

Javascript 角度指令(不作为HTML呈现),javascript,html,angularjs,Javascript,Html,Angularjs,我对Angular比较陌生,很难将指令输出呈现为HTML(反之为文字字符串) HTML中的指令: 指令: app.directive("odometerDisplay",function($compile){//distribute bigNumber digits into individual table cells var linkFunction = function(scope, element, attributes){ scope.bigNum = attributes["odo

我对Angular比较陌生,很难将指令输出呈现为HTML(反之为文字字符串)

HTML中的指令:

指令:

app.directive("odometerDisplay",function($compile){//distribute bigNumber digits into individual table cells
var linkFunction = function(scope, element, attributes){
 scope.bigNum = attributes["odometerDisplay"];
 var oTbl="<table><tr>";//start the table

 for(var a=0;a<scope.bigNum.length;a++){//build table cells with digits as content
  oTbl+= scope.bigNum[a]!== "" ? "<td class=\"oCell\">"+scope.bigNum[a]+"</td>":'';
 }

 oTbl+="</tr></table>";//finish the table
 var markUp=$compile(scope)(oTbl);//compile
 element.append(markUp);//append to DOM
}
 return {
    restrict:"A",
    template:'<div>{{oTbl}}</div>',
    link:linkFunction
  }
});
app.directive(“odometerDisplay”),函数($compile){//将大数字分配到各个表单元格中
var linkFunction=函数(范围、元素、属性){
scope.bigNum=属性[“odometerDisplay”];
var oTbl=“”;//启动表

对于(var a=0;aplese.消除与问题无关的任何问题。如果您的问题不是关于编译器错误,请确保没有编译时错误。我刚刚对您的问题做了一个简单的说明。检查此项了解如何将$compile与html一起使用…非常好!!非常感谢您的快速响应和清晰的回答。非常感谢。我将我会尽快实施并提供反馈。您的解决方案非常有效(非常感谢)。除了此解决方案,我遇到了另一个问题,但我发现了“$observe”函数(作为解决方案)。我在$scope中放置了一个值,然后在页面上作为指令中的属性使用;但在某个数据集完成加载(该值是数据集的长度)之前,该属性不可用。我不断获取属性的“未定义”,直到发现“$observe”函数(attributes.$observe('myAttribute',function()){….在这里执行操作,因为现在属性值已加载/更改..}。