动态元素上添加指令,这并不尚不存在 [英] Dynamically add directive on an element that doesnt exist yet

查看:249
本文介绍了动态元素上添加指令,这并不尚不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个插件来引导我与angularJS下拉列表。我遇到的问题是,他们想要的code相的东西。

I'm using this plugin to bootstrap my dropdown with angularJS. The issue I'm having is that the code they want looks something to

<ol class="nya-bs-select" ng-model="City" name="city" required>

                <li nya-bs-option="city in subCities ">

                    <a>{{ city.name }}</a>
                </li>
            </ol>

来产生类似

    <ol ng-model="City" class="nya-bs-select ng-pristine ng-untouched btn-group ng-invalid ng-invalid-required">               
      <button type="button" class="btn btn-default dropdown-toggle"><span class="pull-left filter-option">- Select -</span>&nbsp;<span class="caret"></span></button>
      <div class="dropdown-menu open">
          <ul class="dropdown-menu inner">
            <li><a>- Select -</a></li>
            <li nya-bs-option="city in subCities" class="ng-scope nya-bs-option">
                        <a tabindex="0" class="ng-binding">CityName</a>
            </li>
          </ul>
      </div>
</ol>

正如你可以看到它增加了一个按钮元素为&LT的子女; OL&GT;
我怎么能听为nyaBsSelect指令,这样,当它创建&LT;按钮&GT; 元素,我想添加一个 NG-禁用指令作为按钮的属性?

As you can see it adds a "button" element as a child of <ol>. How can I "listen" for the "nyaBsSelect" directive so that when it creates the <button> element, I want to add a ng-disabled directive as the button's attribute?

推荐答案

您可以为NYA-BS-选择相同的元素增加一个指令。该指令可以找到按钮添加属性。然而,当你想添加一个指令,因为属性你可能要做$添加属性按​​钮后的编译。让你的指令插件指令之后执行,您可以修改的优先级。
我没有看过成插件。我想你也可以修改插件来添加更多的属性和NG禁用按钮,结合两者。

You can add one more directive in the same element as nya-bs-select. That directive can find the button and add the attribute. However as you want to add a directive as attribute you might have to do $compile of button after adding the attribute. You can modify priority so that your directive executes after plugin directive. I have not looked into the plugin. I guess you could also modify the plugin to add one more attribute and ng disabled to button and bind both.

这篇关于动态元素上添加指令,这并不尚不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆