angular js: accessing $scope from jQuery

前端 未结 4 1522
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 07:16

There are several questions like this in stackoverflow. I know. Tried all the answers, but still no luck. My html :

    
4条回答
  •  醉酒成梦
    2021-01-02 07:36

    Assume the model value is return from a $http request.

    In the controller you have 3 functions:

    function getGameContentSuccessCallback(){
       doSuccessCallback();
    }
    
    function getGameContentErrorCallback(){
      doSth()
    }
    
    function getGameContent(){
      GameContentService.GetGameContent(submitData,getGameContentSuccessCallback,getGameContentErrorCallback)
    
    }
    

    then you define doSuccessCallback in jQuery

    var doSuccessCallback = function(){   
       var country  = angular.element("#headline-game").scope().gameContent.headline;   
       alert(country );   
    }
    

提交回复
热议问题