javascript - Why do I get Error: [$injector:modulerr] http://errors.angularjs.org/1.6.5/$injector/modulerr? -
this question has answer here:
i'm trying load data sql database using mvc5 , angularjs. back-end code works fine , can data it's not being populated table.
my index.cshtml looks this:
@{ viewbag.title = "index"; } <h2>index</h2> <div ng-app="myapp"> <div ng-controller="studentctrl"> <table class="table table-striped table-bordered table-hover table-checkable datatable"> <thead class="grid-top-panel"> <tr> <th>studentid</th> <th>first name</th> <th>last name</th> <th>email</th> </tr> </thead> <tbody> <tr ng-repeat="datamodel in students"> <td>{{datamodel.studentid}}</td> <td>{{datamodel.firstname}}</td> <td>{{datamodel.lastname}}</td> <td>{{datamodel.email}}</td> </tr> </tbody> </table> </div> </div> <script src="~/scripts/angular.js"></script> <script src="~/scripts/angular-route.js"></script> <script src="~/scriptsng/module/app.js"></script> <script src="~/scriptsng/controller/studentcontroller.js"></script> <script src="~/scriptsng/services/studentservice.js"></script> app.js:
var app; (function () { 'use strict'; app = angular.module('myapp', ["ngroute"]); })(); studentservice.js:
app.service('studentservice', function ($http) { //**********----get record----*************** var urlget = ''; this.getall = function (apiroute) { urlget = apiroute; return $http.get(urlget); } }); studentcontroller.js:
app.controller('studentctrl', ['$scope', 'studentservice', // inject studentservice inject because call getall method student function ($scope, studentservice) { // base url var baseurl = '/api/student/'; // student databse $scope.getstudents = function () { var apiroute = baseurl + 'getstudents/'; var _student = studentservice.getall(apiroute); _student.then(function (response) { $scope.students = response.data; }, function (error) { console.log("error: " + error); }); } $scope.getstudents(); }]); some posts suggested add angular-route script on index page , inject ngrouter library module. did , i'm still getting same error:
error: [$injector:modulerr] http://errors.angularjs.org/1.6.5/$injector/modulerr?
what doing wrong?
the module, controller , services scripts being loaded wrong folder weren't coming through. changed them referenced correct scripts folder
Comments
Post a Comment