Dynamically generate modals with MobileAngularUI

醉酒当歌 提交于 2019-12-11 10:44:49

问题


I am using the Mobile Angular UI framework for my mobile web-app.

This Page explains the directive on how to generate modals (they slightly change the bootstrap framework)

I manage to reproduce the example, however when I wrap the directive in a ng-repeat to generate multiple modals, it is not working any more

  <div ui-content-for="modals">
    <div   ng-repeat="p in UseCaseCtrl.getProjects()" >
      <div class="modal" ui-if="modal{{ p.getId() }}" ui-state="modal{{ p.getId() }}">
        <div class="modal-backdrop in"></div>
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button class="close" 
                      ui-turn-off="modal{{ p.getId() }}">&times;</button>
              <h4 class="modal-title">{{ p.getName() }}</h4>
            </div>
            <div class="modal-body">

                ...Lorem...

            </div>
            <div class="modal-footer">
              <button ui-turn-off="modal{{ p.getId() }}" class="btn btn-default">Close</button>
              <button ui-turn-off="modal{{ p.getId() }}" class="btn btn-primary">Save changes</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>        

As far as I experienced, the problem seems to come from ui-state="modal{{ p.getId() }}, as it works again when I hardcode only that one (i.e., set ui-state="modal1")

Am I missing something? Any workaround to generate modals with ng-repeat?

Thanks


回答1:


I use ng-click = "functionName(p.getId()) in controller instead of ui-turn-on="modal{{ p.getId() }}.

Details:

$scope.functionName = function (id) {
    SharedState.initialize($rootScope, 'modal'+id); 
    $rootScope.Ui.turnOn( 'modal'+id);
}; 

note: you need injection SharedState in controller.

I done it and success!



来源:https://stackoverflow.com/questions/32400236/dynamically-generate-modals-with-mobileangularui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!