2014-04-03 83 views
0

從角服務調用IBM工作燈工作燈和角度服務

我的角度服務調用工作燈適配器

.factory('Profile', [ 
       function() { 
       return { 

       loadUserProfileSuccess:function(result){ 
        if(result.statusCode = 200) 
         console.log("Succes"); 

       }, 

       loadUserProfileFailure:function (result){ 
         console.log("failure"); 

       }, 
        getUserProfile: function($rootScope,user){ 

       var invocationData = { 
        adapter : 'RSSReader', 
        procedure : 'find_or_create', 
        parameters : [user.name,user.email] 
       }; 

       WL.Client.invokeProcedure(invocationData,{ 
        onSuccess : loadUserProfileSuccess, 
        onFailure : loadUserProfileFailure 
          }); 
       }, 
      }//end return 

}]); 

當調用工作燈適配器時,下面的代碼失敗,似乎一切都很正常上程序方面。但角度抱怨,即使回調函數loadUserProfileSuccess定義...

Error: Can't find variable: loadUserProfileSuccess 
[email protected]:///... 

回答

1

您試圖訪問loadUserProfileSuccess不正確。移動內聯函數:

WL.Client.invokeProcedure(invocationData, { 
    onSuccess: function (result) { 
    if (result.statusCode = 200) console.log("Succes"); 
    }, 
    onFailure: function (result) { 
    console.log("failure"); 
    } 
}); 

或者宣佈外界物體的你返回:

factory('Profile', [ 

function() { 
    var loadUserProfileSuccess = function (result) { 
     if (result.statusCode = 200) console.log("Succes"); 

    }; 
    var loadUserProfileFailure = function (result) { 
     console.log("failure"); 

    }; 
    return { 

     loadUserProfileSuccess: loadUserProfileSuccess, 

     loadUserProfileFailure: loadUserProfileFailure, 
     getUserProfile: function ($rootScope, user) { 

      var invocationData = { 
       adapter: 'RSSReader', 
       procedure: 'find_or_create', 
       parameters: [user.name, user.email] 
      }; 

      WL.Client.invokeProcedure(invocationData, { 
       onSuccess: loadUserProfileSuccess, 
       onFailure: loadUserProfileFailure 
      }); 
     }, 
    } //end return 


}]);