angularjs ng-show with promise expression

后端 未结 3 894
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 11:50

I\'m using ng-show with an expression that resolves to a promise that resolves to a boolean. When I do this I get the 10 digest iterations overflow.

3条回答
  •  自闭症患者
    2021-01-17 12:24

    Plunker: http://plnkr.co/edit/NvjP5qHafhyIWXXotBej?p=preview

    This works as I think you intended it to. $q.when() returns a promise object, so ng-show is not getting a boolean value; it's getting a promise object.

    Updated template:

      
        

    non promise

    promise

    Updated Ctrl:

      $scope.returnsABoolean = ()->
        true
    
      promise = $q.when(false)
      promise.then((val) ->
        $scope.returnsAPromiseThatResolvesToABoolean = val)
    

提交回复
热议问题