使用工厂在应用程序中使用Restangular

时间:2015-07-30 09:10:46

标签: angularjs restangular

我在这里创建了一个工作的demoapp,其中我使用了restangular

它工作得很好但是当我厌倦了在工厂实现demoapp时,数据似乎没有来,我无法检查出这个可能的错误

/* the file containing my json object*/


[
{"id":1,
"subject":"#aashima"
},
{"id":2,
"subject":"#aansh"
},
{"id":3,
"subject":"#artle"
},
{"id":4,
"subject":"#harish"
}
]
<!doctype html >
<html ng-app="app">
<head>
    <meta charset="UTF-8">
	
    <title>Restangular</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">  
	<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.16/angular.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script>
</head>
<body>
    <div ng-controller="IndexCtrl as omega" ng-cloak>
        <ul>
            <li ng-repeat="result in omega.people">
                <span ng-bind="result.subject"></span>
            </li>
            
        </ul>
        <span ng-bind="omega.harish"></span>
    </div>
 
    <script>
        var app = angular.module('app', ['restangular'])
        app.config(function(RestangularProvider) {
            RestangularProvider.setBaseUrl("\js");
            
        app.controller('IndexCtrl', function(  testFactory) {
            var self=this;    
        testFactory.getFriendList.then(function (homeFriends) {
            self.people=homeFriends;
            console.log(self.people);
         }); 
            
        });
        
    app.factory('testFactory', ['Restangular', function (Restangular) {
        return {
            getFriendList: Restangular.all('emp.json').getList()
        }
    }]);

        
    
        
        
    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
<!doctype html >
<html ng-app="app">
<head>
    <meta charset="UTF-8">
	
    <title>Restangular</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">  
	<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.16/angular.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script>
</head>
<body>
    <div ng-controller="IndexCtrl as omega" ng-cloak>
        <ul>
            <li ng-repeat="result in omega.people">
                <span ng-bind="result.subject"></span>
            </li>
            
        </ul>
        <span ng-bind="omega.harish"></span>
    </div>
 
    <script>
        var app = angular.module('app', ['restangular'])
        app.config(function(RestangularProvider) {
            RestangularProvider.setBaseUrl("\js");
            
             
        
            });
            
        app.controller('IndexCtrl', function( Restangular, testFactory) {
            var self=this;     
            
            
            Restangular.all('evm.json').getList().then(function(result) {
            self.people = result;
            });   
           
        testFactory.getFriendList.then(function (homeFriends) {
            console.log(self.people);
            self.people=homeFriends;
           
         }); 
            
        });
        
    app.factory('testFactory', ['Restangular', function (Restangular) {
        return {
            getFriendList: Restangular.all('emp.json').getList()
        }
    }]);
&#13;
&#13;
&#13;

</script>

他们是一些语法问题,我已经纠正,现在你的应用程序将运行