Angularjs手风琴

时间:2015-12-14 13:19:52

标签: javascript angularjs

我使用以下链接在angular中创建Accordion。在那里,我从控制器发送HTML结构。但在观点方面,它并没有告诉我Accordion。以下是示例代码:

 var final='<uib-accordion close-others="oneAtATime"><uib-accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">This content is straight in the template.</uib-accordion-group>'

在观看方面,我显示的数据如下:

<div ng-bind-html="final"></div>

我想从控制器端发送HTML结构。 请帮我解释为什么它没有正确显示手风琴?

2 个答案:

答案 0 :(得分:0)

您显示的unsigned randomUns(unsigned minV, unsigned maxV, default_random_engine::result_type seed = 0){ static default_random_engine e(seed); static default_random_engine::result_type last_seed = seed; if (seed != last_seed){ e = default_random_engine(seed); last_seed = seed; } uniform_int_distribution<unsigned> u(minV, maxV); return u(e); } 变量是否已定义?在这种情况下,您的观点不知道那是什么 - &#39; final&#39;。它未定义。

尝试使用范围声明它:final在这种情况下,您的视图会看到$scope.final='<uib-accordion close-others="oneAtATime"><uib-accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">This content is straight in the template.</uib-accordion-group>'final并且可以阅读。

另一种方法(如果您不想使用$ scope)使用$scope.finalthis将其声明为控制器变量。您可以从以下视图中调用它:this.final='<uib-accordion close-others="oneAtATime"><uib-accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">This content is straight in the template.</uib-accordion-group>'

答案 1 :(得分:0)

您必须$compile此变量才能在视图上呈现。您可以创建包含$compile service的指令以进行渲染。然后,您可以在该视图上使用它来呈现变量中的动态DOM。

指令:

app.directive('compile', function ($compile) {
  return {
    restrict: 'A',
    replace: true,
    link: function (scope, elem, attrs) {
      scope.$watch(attrs.compile, function(html) {
        elem.html(html);
        $compile(elem.contents())(scope);
      });
    }
  };
});

像;

<div compile="final"></div>

当然,您不要忘记将最终变量设置为$ scope。等;

$scope.final = final;

$scope.final='<uib-accordion close-others="oneAtATime"><uib-accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">This content is straight in the template.</uib-accordion-group>';

我认为您需要查看that answer