【问题标题】:need to declare all the error messages globally in a property file需要在属性文件中全局声明所有错误消息
【发布时间】:2017-03-11 03:17:42
【问题描述】:
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

如果任何人都可以给我一个想法,是否有可能在角度上,谢谢你

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

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    我认为……这是可能的。哈哈!

    您可以通过 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.

    让我们玩得开心。 :)

    【讨论】:

      猜你喜欢
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多