angularjs - Must give users a success or error message -


when eg. sends right out , text json must provide true. if gives true must make success message. if not fit, must go , give error.

the problem right should return if successful or error.

it's send whether have solved problem right or wrong in relation time , text have written.

this how have built website in mvc. asp.net

<input type="hidden" ng-init="getid='@model.id'" ng-model="getid" />     <div ng-repeat="module in newslist" style="clear:both; margin:7px 0; min-height:110px; margin:5px 0;">         <div class="col-md-8">              <div ng-show="succes">                 succes             </div>             <div ng-show="error">                 error             </div>               <div style="clear:both; margin-bottom:10px;" class="col-md-10">                 <input type="text" ng-model="module.text" class="form-control" placeholder="write answer here" name="text" />                 <button ng-click="checkvalue(module)" class="btn btn-primary pull-right" style="margin:6px 0;">                     check answer                 </button>             </div>         </div>     </div> 

load.js

var app = angular.module('opgaver', []); app.controller('opgavercheck', function ($scope, $http) {       $scope.checkvalue = function (module) {         //console.log("hello world " + module.id + " - " + module.text);          //post         $scope.$watch("id", function() {             var url = "/opgaver/kategori/" + $scope.id + "/" + module.text;              $http.get(url).success( function(response) {                 //return true or false .html view. problem here!!              });         })     } }); 

jsonresult here:

[httpget]     public jsonresult checkopgave(int id, string text)     {         var db = helpers.helpertotables.dbvalue;         var valuetext = text.tolower();          var check = db.lektioneropgaves.firstordefault(i => i.fk_lektionerid == id && i.correctanswer.equals(valuetext));         if (check != null)         {             //succes             return json("succes");         }         else         {             //error             return json("error");         }     } 

you should assign json return variable, use in ng-show.

so example:

$http.get(url).success( function(response) {             //return true or false .html view. problem here!!             $scope.jsonmessage = response;          }); 

and in html want this:

<div ng-show="jsonmessage=='success'">             success         </div>         <div ng-show="jsonmessage=='error'">             error         </div> 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -