【问题标题】:How use modals in angular如何在角度中使用模态
【发布时间】:2015-05-30 20:46:20
【问题描述】:

我有 4 个按钮,它们调用模态引导窗口,当我这样做时,函数会使用 $scope 的变量加载 html-temptale,但是模态窗口不适用于 $scope,我之前问过这个问题并且有回答使用指令,但坦率地说我不明白它是如何工作的,这是一个例子

<div class="infBox" data-toggle="modal" data-target="#myModal" ng-click="modal('Modals/modal2', row.Name)">
            <h4>BUILD</h4>
            <div>
                <img ng-class="{opac: row.Commit.Build.Debug == false}" src="IMG/computer-md.png">
                <img ng-class="{opac: row.Commit.Build.Release == false}" src="IMG/computer-md.png">
            </div>
            <span class="debug">Debug</span><span>Release</span>
            <span class="time">{{row.Commit.Build.Timefin}}</span>
        </div>

这是 div 按钮

<div  class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
        </div>
            <div  class="modal-body">

            </div>
        </div>
    </div>
</div>

这是模态窗口

$scope.modal = function(path, name){
    $scope.ModalObj = $scope.Objects[FindNumber(name, $scope.Objects)];
    $http.get(path).success(function(data) {
         $scope.modalData = data;
    });

};

这是一个加载temptale的函数

<h4>BUILD</h4>
    <div>
        <img ng-class="{opac: ModalObj.Commit.Build.Debug == false}" src="IMG/computer-md.png">
        <img ng-class="{opac: ModalObj.Commit.Build.Release == false}" src="IMG/computer-md.png">
    </div>
    <span class="debug">Debug</span><span>Release</span>
    <span class="time">{{ModalObj.Commit.Build.Timefin}}</span>

这是诱惑

【问题讨论】:

  • 除了@Sumeet Gohil 的回答之外,还有一个AngularJS 模态实现(但是没有引导标记),它处理模态中单独的$scope - github.com/likeastore/ngDialog

标签: javascript angularjs twitter-bootstrap


【解决方案1】:

这是你最后一篇帖子,Nishi 给你的建议非常好

Problems with modal and ng-bind-html

如果您不明白,请考虑一些建议。

  1. Angular 和 jQuery 并存,您可以填补这一空白,也可以采用任何一种技术。
  2. 如果你想使用 Bootstrap Modal 那么你需要使用 Angular Modal https://github.com/btford/angular-modal
  3. 正如 Nishi 在您上一篇文章中所发布的那样,我会很好地工作,您只需更改几行即可。

    writeYourAppName.directive('modal', function () {
      return {
         template: 'Your Modal Window Code',
    

并使用控制器将值传递给模型

【讨论】:

    【解决方案2】:

    您可能需要使用angular-ui modal

    【讨论】:

      猜你喜欢
      • 2021-07-02
      • 1970-01-01
      • 2017-06-13
      • 2021-09-25
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多