简体   繁体   English

如何解决bootstrap.js和angularjs的角度列表之间的冲突

[英]How to resolve a conflict between bootstrap.js and angularjs for angular lists

This is my html code 这是我的html代码

<div class="form-group">

     <select ng-model="modSelectedState" id="selectState" name="selectState"
          ng-options="state as state.full_name for state in states">
          <option value="">Select State...</option>                                         </select>
     </div><!-- /.form-group -->

It renders as expected until i add this line to my code: 它将按预期方式渲染,直到我在代码中添加以下行:

 <script type="text/javascript" src="scripts/bootstrap/js/bootstrap.min.js"></script>

At which point all i see when i render the page is the default option ("select state"). 在这一点上,我渲染页面时所看到的都是默认选项(“选择状态”)。 When I remove bootstrap.js everything renders as expected - that is I see the list of all states. 当我删除bootstrap.js时,所有内容都会按预期呈现-也就是说,我看到了所有状态的列表。

This is how I load the code in the controller 这就是我在控制器中加载代码的方式

 $http.get('./data/states.js').success(function (data) {
        $scope.states = data.locations;
    });

states.js is stored locally. States.js存储在本地。

I have some other angular elements on the page and they all work fine. 我在页面上还有其他一些角度元素,它们都可以正常工作。 I also tried to play with the loading order (ie load bootstrap before angular and vice versa) but the result is the same - the list renders fine without bootstrap and it doesn't render with bootstrap. 我也尝试使用加载顺序(即在角度之前加载引导,反之亦然),但是结果是一样的-列表在没有引导的情况下可以很好地呈现,而在没有引导的情况下不会呈现。

Is there any known conflict between those two libraries when it comes to binding lists? 在绑定列表方面,这两个库之间是否存在任何已知的冲突? Is there any known workaround? 有任何已知的解决方法吗?

You need to use controls specially prepared to work with bootstrap and angular ... otherwise you will not only get this type of unexpected issues, but you'll get other type of issues based on the fact that you are trying to make your own implementations when there already exist validated ways of working with javascript libraries. 您需要使用专门为与引导程序和angular一起使用而准备的控件 ...否则,您不仅会遇到这类意外问题,而且还会因尝试自己实现自己的事实而遇到其他类型的问题。当已经存在使用javascript库的经过验证的方法时。 Best regards. 最好的祝福。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM