Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么是正确的方法,以消除HTML内容的角度?_Javascript_Angularjs_Angularjs Directive_Angularjs Ng Transclude - Fatal编程技术网

Javascript 什么是正确的方法,以消除HTML内容的角度?

Javascript 什么是正确的方法,以消除HTML内容的角度?,javascript,angularjs,angularjs-directive,angularjs-ng-transclude,Javascript,Angularjs,Angularjs Directive,Angularjs Ng Transclude,我需要将包含注销按钮的div转换到我的一个自定义选择下拉指令中,但是转换的内容最终不是在指令模板内部,而是在指令模板外部。如果我只是将一段字符串(例如somecontent)放在指令中,而不是放在HTML中,那么transclude就起作用了。但我一把HTML放进去,它就不起作用了 所以我的问题是,将HTML内容转换成指令模板的正确且最简单的方法是什么 指令: coForms.directive('coSelect', [function() { return { re

我需要将包含注销按钮的
div
转换到我的一个自定义选择下拉指令中,但是转换的内容最终不是在指令模板内部,而是在指令模板外部。如果我只是将一段字符串(例如
somecontent
)放在指令中,而不是放在HTML中,那么transclude就起作用了。但我一把HTML放进去,它就不起作用了

所以我的问题是,将HTML内容转换成指令模板的正确且最简单的方法是什么

指令:

coForms.directive('coSelect', [function() {

    return {
        restrict: 'E',
        scope: {},
        transclude: true,
        controller: 'CoFormsCtrl',
        controllerAs: 'co',
        templateUrl: 'app/views/components/co-forms/co-select.html',
        link: function(scope, element, attrs, ctrl) {


        }
    };
}]);
用法:

<!-- This is inside a loop, where it should only appear for the first row, hence the ng-if="$first" -->
<co-select>
    <div ng-if="$first" class="logout-wrapper">
        <a ng-href="/logout">
            <button class="btn-danger plain">Logout</button>
        </a>
    </div>
</co-select>

模板:

<div>
  <ul>
    <li>The options list yo</li>
  </ul>
  <!-- Transcluded content should go here -->
  <div ng-transclude></div>
</div>

  • 选项列表哟

请您提供一个提示,快速一看,转换看起来很好如果=“$first”应该实现什么?删除它,或者设置一个计算结果为true的条件,您的转换工作正常。如果您只想在模板中循环的第一次迭代中转移内容,那么我认为您需要在转移之外测试$first。@Duncan我添加了一条注释说明$first存在的原因。在中正常工作。