Accessing angular directive (element)'s text inside the template

纵饮孤独 提交于 2019-12-04 02:55:26

You need to use ngTransclude:

app.directive('myDir', function(){
  return {
    restrict: "E",
    transclude: true,
    templateUrl: "myDirTemplate.html",
    replace: true
  }
});

and then your external template becomes something similar to:

<div>The value is: <span ng-transclude></span></div>

View the code working here: http://plnkr.co/edit/EuT5UlgyxgM8d54pTpOr?p=preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!