2016-10-28 75 views
-3
I need to declare all the error message like (401,200 etc....) in a property file, need to access them later where ever its required 

in the below format mostly 

key=messsage 
404 = This request caon't be processed 
200 = your request is successfull 

全局声明所有的错误信息是不是posssible在角ifso可以在任何身体给我一个想法,感谢ü需要在属性文件

============ ================================================== ========

回答

0

我认为......这是可能的。大声笑 !

您可以通过JSON文件声明全局值。 (保存在你的服务器上)

See the JSON format here

例子:

globalvalue.json

[ 
    { 
    "key": 404, 
    "message": "This request caon't be processed" 
    }, 
    { 
    "key": 200, 
    "message": "your request is successfull" 
    } 
] 

而接下来你刚才读的是通过你的服务器全局值它存储在JSON文件。

角代码:

angular 
.module('app.services', []) 
.factory('Friend', function ($http) { 
    return { 
     get: function() { 
      return $http.get('/globalvalue.json'); 
     } 
    }; 
}); 

然后用你的工厂是这样的:

.angular 
.module('app.controllers', ['app.services']) 
.controller('yourCtrl', function ($scope, Friend) { 
    Friend.get().then(function (msg) { 
     $scope.msg = msg; 
    }); 
}); 

铬。 Reading data from JSON file in Angularjs

让我们开心。 :)