You must Sign In to post a response.
  • Category: ASP.NET

    Issue in angular js in html page

    I am new to angular js. Please find the below script which I used in html page.
    Web api is working fine and it is returning data as JSON format.

    <script>

    var app = angular.module('PatientApp', []);
    console.log('hello');

    app.controller('PatientController', function ($scope, $http) {

    $http({ method: 'Get', url: 'http://localhost:53193/api/patient' }).success(function (data) {
    console.log('hello');
    $scope.patients = data; // response data
    }).
    error(function (data) {
    console.log(data);
    });
    });

    </script>

    when I ran this script in html page, it is not even coming into this script


    Can you please let me know what is the issue here.
  • #767003
    Hi



    <div ng-app="">

    <p>Name: <input type="text" ng-model="name"></p>
    <p>You wrote: {{ name }}</p>

    </div>



    refer this url
    "w3schools.com/angular/angular_examples.asp"

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767013
    Hi,
    First check following reference exist in your application or not:

    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

    After that check whether you had provided method name inside API call:
    $http({ method: 'Get', url: 'http://localhost:53193/api/apiname/apimethodname' }).

  • #767015
    Following may be some possibilities,
    1. You may miss some js file. Make sure you included all the required js files.
    2. The URL http://localhost:53193/api/patien may have issue, that may not work properly.
    3. Check your entire page, and make sure you formatted the page properly some times you may miss "{" or "(". We may not notice that at the run time.

    By Nathan
    Direction is important than speed

  • #767085
    Let me clear some points about JSON and read its input using JavaScript
    A common use of JSON is to read data from a web server, and display the data in a web page, JSON data is written as name/value pairs. Curly brackets indicates objects and square for Array
    here is basic syntax

    "test":[
    {"fname":"abc", "lname":"xxx"},
    {"fname":"pqr", "lname":"yyy"},
    {"fname":"lmn", "lname":"zzz"}
    ]

    //to read above JSON we need below javascript
    var obj = JSON.parse(text);
    document.getElementById("lbl1").innerHTML =
    obj.employees[1].firstName + " " + obj.employees[1].lastName;

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments