Hi;
Return the premise directly from the factory:
* getUsers: **function** () {*
* return $http.get(**'/api/UserAPI?userListType=allUsers'**)*
*;*
*}*
then in controller
*usersFactory.getUsers().**success(**function** (response) {*
* $scope.users =** response;*
*})**.**error(**function** (err) {*
* alert('Error: ' + err);*
*})**;*
On Saturday, January 31, 2015 at 2:41:07 PM UTC+6, 洪秋雲 wrote:
>
> I call the factory function to get data to bind the $scope.users and the
> factory’s function call $http.get(“/api/UserAPI?userListType=allUsers”).
>
> The $http.get(“/api/UserAPI?userListType=allUsers”) response code is 200 ,
> but when I injected the factory to controller and then called the factory
> function that it always show undefined value.
>
> *HTML*
>
> *<**div* *ng-controller**="MyCtrl">*
>
> *<**div* *class**="col-md-4">*
>
> *<**select* *name**="applyUser"* *kendo-combo-box*
> *ng-model**="applyUser"* *ng-options**="user as user.strRoleUserName for
> user in users"></**select**>*
>
> *</**div**>*
>
> *</**div**>*
>
>
>
> *Java Script*
>
> *<**script**>*
>
> * angular.module(**"requestApp"**, [**"kendo.directives"**]).factory(*
> *"usersFactory"**, **function** ($http) { *
>
> *return** {*
>
> * getUsers: **function** () {*
>
> * $http.get(**'/api/UserAPI?userListType=allUsers'*
> *).success(**function** (response) {*
>
> *return** response;*
>
> * });*
>
> * },*
>
> * };*
>
> * }).controller(**"MyCtrl"**, **function** ($scope, $http,
> usersFactory) {*
>
> * $scope.users = [];*
>
> * $scope.users = usersFactory.getUsers(); *
>
> * console.log($scope.users);*
>
> * });*
>
> *</**script**>*
>
> The $scope.users get value from usersFactory.getUsers , but it get
> undefined
>
> I had stuck the problem for a long time, please help me
>
> Thanks.
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.