Scope issues with Angular UI modal

后端 未结 5 610
萌比男神i
萌比男神i 2020-12-02 06:25

I\'m having trouble understanding/using the scopes for an angular UI modal.

While not immediately apparent here, I have the modules and everything set up correctly

相关标签:
5条回答
  • 2020-12-02 06:48
    $scope.open = function () {
    
              var modalInstance = $uibModal.open({
                  animation: $scope.animationsEnabled,
                  templateUrl: 'myModalContent.html',
                  controller: 'salespersonReportController',
                  //size: size
                  scope: $scope
                });
    
          };
    

    it works for me scope: $scope thank u Jason Swett

    0 讨论(0)
  • 2020-12-02 06:53

    When nested scopes are involved, do not bind <input>s directly to members of the scope:

    <input ng-model="name" /> <!-- NO -->
    

    Bind them to at least a level deeper:

    <input ng-model="form.name" /> <!-- YES -->
    

    The reason is that scopes prototypically inherit their parent scope. So when setting 1st level members, these are set directly on the child scope, without affecting the parent. In contrast to that, when binding to nested fields (form.name) the member form is read from the parent scope, so accessing the name property accesses the correct target.

    Read a more detailed description here.

    0 讨论(0)
  • 2020-12-02 06:53

    Update Nov 2014:

    Actually your code should work after upgrading to ui-bootstrap 0.12.0. Transcluded scope is merged with controller's scope so no more need for $parent or form. stuff.

    Before 0.12.0:

    The modal uses transclusion to insert its contents. Thanks to ngForm you can control the scope by name attribute. So to escape transcluded scope just modify the form this way:

    <form name="$parent">
    

    or

    <form name="$parent.myFormData">
    

    The model data will be available in controller scope.

    0 讨论(0)
  • 2020-12-02 07:10

    I got mine to work like this:

    var modalInstance = $modal.open({
      templateUrl: 'partials/create.html',
      controller: 'AppCreateCtrl',
      scope: $scope // <-- I added this
    });
    

    No form name, no $parent. I'm using AngularUI Bootstrap version 0.12.1.

    I was tipped off to this solution by this.

    0 讨论(0)
  • 2020-12-02 07:14

    I add scope:$scope then it works .Cool

    0 讨论(0)
提交回复
热议问题