赞
踩
我的角度服务有问题.
我的服务有下一个代码:
app.service("Utilidades", ['$http', '$window', function ($http, $window) { return { Get: function (urlAbsoluta, parametros, callback) { var Utilidades = this; $http .get(app.UrlBase + urlAbsoluta, parametros) .then(function (data) { var Datos = angular.fromJson(data); Utilidades.GuardarToken(Datos.Token); callback(Datos); }); }, ObtenerMenu: function () { var Utilidades = this; Utilidades.Get("Administracion/Api/Usuarios/Menu", {}, function (Datos) { Datos = angular.fromJson(Datos.data); if (Datos.Error == "") { return Datos.Resultado; } else { return ""; } }); } } }]);
然后,在我的控制器中,我有下一个代码:
app.controller('LoginCtrl', ['$scope', '$http', '$location', 'Utilidades', function Iniciador($scope, $http, $location, Utilidades) { var Li = this; Li.Usuario = ""; Li.Contrasena = ""; Li.Error = ""; Li.MenuItems = []; Li.Menu = function () { Li. MenuItems = Utilidades.ObtenerMenu(); } }] );
当我运行它时,Li.MenuItems有未定义的值,我不知道为什么.
你的return
语句是一个函数里面的ObtenerMenu
方法,所以ObtenerMenu
方法实际上并不返回任何东西.您需要提供一种访问结果值的方法:
服务
app.service("Utilidades", ['$http', '$window', function ($http, $window) { return { Get: function (urlAbsoluta, parametros) { var Utilidades = this; // v------------ return statement here return $http .get(app.UrlBase + urlAbsoluta, parametros) .then(function (data) { var Datos = angular.fromJson(data); Utilidades.GuardarToken(Datos.Token); // v------------ return statement here return Datos; }); }, ObtenerMenu: function () { var Utilidades = this; // v------------ return statement here return Utilidades.Get("Administracion/Api/Usuarios/Menu", {}) .then(function (Datos) { if (Datos.Error == "") { return Datos.Resultado; } else { return ""; } }); } }; }]);
在控制器中
Li.Menu = function () { Utilidades.ObtenerMenu() .then(function (resultado) { Li. MenuItems = resultado; }); }声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/iOS/detail/8243
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。