asp.net mvc - Consuming REST Web Api service from angularjs -
Ça va?
i'm developing programme should able recover info mvc .net server , visualize in angularjs front-end. unfortunately isn't working. here's code:
mvc controller:
using system; using system.collections.generic; using system.linq; using system.net; using system.net.http; using system.web.http; using newtonsoft.json; using mvcprueba.models; using system.diagnostics; using system.web.mvc; namespace mvcprueba.controllers { public class valuescontroller : apicontroller { #region camposprivados private static logica l; #endregion #region metodosrest // api/values public ienumerable<tablaentrada> get() { debug.writeline("llamada getall"); homecoming l.gettelist(); //return new string[] { "value1", "value2" }; } /*public jsonresult get() { homecoming l.gettelist(); }*/ // api/values/5 public string get(int id) { homecoming l.getsinglete(id); //return "value"; } // post api/values public void post([frombody]string value) { l.addnewte(value); } // set api/values/5 public void put(int id, [frombody]string value) { l.modifyexistingte(id, value); } // delete api/values/5 public void delete(int id) { l.deleteexistingte(id); } #endregion #region metodosinicio public static void app_start() { l = logica.filllistate(); } #endregion } }
and, angularjs factory:
(function () { var etfactory = function ($http, $window) { var tes = []; var factory = {}; factory.bidaligetallrequest = function () { $http.get('http://localhost:50059/api/values'). success(function (response) { tes = response; $window.alert("http request ok, values:"+"\n"+tes[0].descripcion+"\n"+tes[1].descripcion+"\n"+tes[2].descripcion); }).error(function () { $window.alert("error"); }); } factory.gettes = function () { /*$http.get('http://localhost:50059/api/values'). success(function (response) { tes = response; $window.alert("ok.\n"+movimientos[0].descripcion); homecoming tes; });*/ homecoming http.get('http://localhost:50059/api/values'); } factory.anadirnuevo = function (nuevo) { } /* factory.cambiarvalor = function () { if (a.valor == "a") { b.visible = false; c.enabled = "checked"; movimientos[4].dominio = ["opcion1","opcion2","opcion3","opcion4","opcion5"]; } else { b.visible = true; c.enabled = ""; movimientos[4].dominio = ["opcion1","opcion2"]; } };*/ homecoming factory; } controlcajaapp.factory('etfactory', etfactory); }());
i know http request gets back-end, i've made tries. thing in front-end doesn't alter anything. ideas?
edit:
a couple of screenshots of developer tools network tab , console:
http://i.stack.imgur.com/w815y.jpg http://i.stack.imgur.com/usz0f.jpg
edit2:
this controller, calls factory:
(function () { var controletctrl = function (etfactory, $scope, $http, $window) { var scope = this; scope.titulo = "mi tabla de entradas"; scope.movimientos = etfactory.gettes(); //scope.movimientos = []; scope.funciones = {}; scope.cargardatos = function () { /*etfactory.bidaligetallrequest();*/ $http.get('http://localhost:50059/api/values'). success(function (response) { this.movimientos = response; $window.alert("ok.\n"+movimientos[0].descripcion); }); } function cargar (){ $http.get('http://localhost:50059/api/values'). success(function (response) { this.movimientos = response; $window.alert("ok.\n"+movimientos[0].descripcion); }); }; scope.funciones.cambiarvalor = function () { etfactory.cambiarvalor(); } scope.funciones.guardarmovimiento = function () { /* var auxcopymov = angular.copy(scope.nuevomovimiento); auxcopymov.tipo = scope.funciones.tipo(auxcopymov); etfactory.postmovimiento(auxcopymov); scope.movimientos = etfactory.getmovimientos(); scope.total = etfactory.gettotal(); scope.nuevomovimiento.importe = 0; */ } } controlcajaapp.controller('controletctrl', ['etfactory', controletctrl]); }());
and html view, utilize variable movimientos controller in ng-repeat:
<section name="et" class="row-fluid"> <form class="form-horizontal text-left"> <fieldset> <div id="legend"> <legend class="">{{controlet.titulo}}</legend> </div> <br> <div> <div class="control-group" ng-repeat="valor in controlet.movimientos" ng-show="valor.visible"> <label class="control-label">{{valor.descripcion}}</label> <input ng-show="valor.tipo_visualizacion == 2" ng-disabled="valor.enabled" type="text" class="input" ng-model="valor.valor" ng-change="controlet.funciones.cambiarvalor()"></input> <select ng-show="valor.tipo_visualizacion == 1" ng-disabled="valor.enabled" name="v" ng-model="valor.valor" ng-options="v v in valor.dominio"></select> <!-- <input type="checkbox" ng-show="valor.tipo_visualizacion == 3" ng-disabled="valor.enabled" type="text" class="input" ng-model="valor.valor" ng-change="controlet.funciones.cambiarvalor()"> --> </div> </div> </fieldset> </form> </section>
change service method this
factory.gettes = function () { var promise = $http.get('http://localhost:50059/api/values'). success(function (response) { tes = response; $window.alert("ok.\n"+movimientos[0].descripcion); homecoming tes; }); homecoming promise; }
and in controller write test
etfactory.gettes().success(function(data){ scope.movimientos = data; });
asp.net-mvc angularjs
No comments:
Post a Comment