shyamseshadri / angularjs-up-and-running

All the source code for the AngularJS Up & Running Book for O'Reilly
MIT License
464 stars 438 forks source link

Javascript Runtime Error: angular is undefined #25

Open carlinwilliams opened 8 years ago

carlinwilliams commented 8 years ago

I am new to Angular. Trying to build a sample appilication with VS.NET 2015 using angularjs. When i try to load my application,I am facing this issue. Appreciate your help. HTML

<meta name="viewport" content="width=device-width" />
<title></title>
<link href="CSS/amelia.bootstrap.min.css" rel="stylesheet" />
<link href="CSS/Site.css" rel="stylesheet" />   
<script src="~/Scripts/angular.js"></script>      
<script src="~/Content/app/Controllers/RegistrationController.js"></script>
<script src="~/Content/app/Resources/RegistrationResource.js"></script>   

In Body:

Controller.js

var app = angular.module('regApp', ['regApp2']); app.controller('RegistrationCtrl', ['$scope', function ($scope, rescountries) {

    $scope.GetCountries = function () {
        var countries = rescountries.GetAllCountries();
        countries.$promise.then(function (data) {
            $scope.countries = data;
            $scope.selectedCountry = 1;
        }, function (error) { $scope.RegistrationResource = false });
    };

}]);

Service.js

var app = angular.module('regApp2', []); app.factory('RegistrationResource', ['$http', function ($http) {
var urlBase = 'http://localhost:62463/';

    var rescountries = {};

    rescountries.GetAllCountries = function () { return $http.get(urlBase + '/api/Registration/GetAllCountries') }
    return rescountries;
}]);

Api call

using WebAPIAngular.DAL; using WebAPIAngular.Entities; using WebAPIAngular.Models; using WebAPIAngular.Controllers; namespace WebAPIAngular.WebAPI { [RoutePrefix("api/Registration")] public class RegistrationController : ApiController { // GET api/GetAllStates/{id} [Route("api/GetAllStates/{id}")] public IEnumerable GetAllStates(int id) { return StateRepository.GetAllStates(id); }

    // GET api/GetAllCountries
    [HttpGet]
    [Route("api/GetAllCountries")]
    public IEnumerable<Country> GetAllCountries()
    {
        return CountryRepository.GetAllCountries();
    }
}

}