如何在模板中设置范围?

时间:2017-01-02 09:27:41

标签: angularjs angularjs-scope

您好我将创建的元素追加到父级:

  container.append(UIService.appendWorkItem(workItem));

UIService

 function appendWorkItem(item) {
         return '<div  layout="column" ng-init=item='+item+' class="md-whiteframe-1dp workItem  workItemName" id='+item._id+'child> <div layout="row"  layout-align="space-between"  ng-click="workItemActivate('+item+')" ng-dblclick="openItemEdit('+item+')"> <div>'+item.name+'</div> <div> <md-icon md-font-icon="zmdi zmdi-share"  title="Has parent child connection"></md-icon> </div> </div> <div class="dragulaParentDOM" > <div dragula="first-bag"  id="'+item._id+'containerWorkItem" class="itemChildContainer"></div> </div> </div>'
    }

我想将scope.item设置为此temlate。我用它

ng-init=item='+item+'  

但它不起作用。怎么做?

1 个答案:

答案 0 :(得分:4)

您必须将ng-init与""一起使用。

ng-init="item='myData'"

你需要compile范围。

container.append($compile(UIService.appendWorkItem(workItem))(scope));