Reputation: 25
my problem is that Error: [$injector:nomod]Module'myApp' is not available!You either misspelled the module name or forgot to load it. ...
I make my project MVC logic. It is my main angular codes
"use strict";
var app=angular.module('myApp',[]);
this is my angular controller codes
app.controller('myCtrl',['$scope','myFactory',function ($scope,userService) {
var self=this;
self.users=[];
getAllData();
function getAllData() {
userService.getAllData()
.then(function (value) {
self.users=value;
},function (reason) {
console.log('Error');
});
}
}]);
and this is my angular service codes
app.factory('myFactory',['$http','$q',function ($http,$q) {
var uri='href="localhost:8080/index"';
var factory=
{getAllData:getAllData};
return factory;
function getAllData() {
var deferred=$q.defer();
$http.get(uri)
.then(function (response) {
deferred.resolve(response.data);
},function (reason) {
deferred.reject(reason);
});
return deferred.promise;
}
}]);
this is my html codes what i used in index.html
<script src="//unpkg.com/angular/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
<script src="https://code.angularjs.org/1.6.9/angular-route.js"></script>
<script src="https://code.angularjs.org/1.6.9/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="/static/angular/app.js"></script>
<script src="/static/userController.js"></script>
<script src="/static/angular/userService.js"></script>
and this is my Controller class maybe help you with something
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@RequestMapping("/index")
public String home(){
return "index";
}
}
Please help me, why i got error? version is higher than 1.3 and script codes written correctly. I have looked internet what talking about script forgot
I added files photo
and this is code in html that i wanted to display my all users in the table
<tbody>
<tr ng-repeat="user in myCtrl.getAllData">
<td ng-bind="user.id"></td>
<td ng-bind="user.name"></td>
<td ng-bind="user.surname"></td>
<td ng-bind="user.phone"></td>
<td ng-bind="user.age"></td>
<td ng-bind="user.note"></td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
Note: It is not full of codes, just part of one
Upvotes: 0
Views: 557
Reputation: 2027
By default spring boot looks for static files in static folder. So you no need to include 'static' in the path. Just reference like below.
<script src="angular/app.js"></script>
<script src="angular/userController.js"></script>
<script src="angular/userService.js"></script>
and I see you are loading angular and angular.min.js twice, it is not required , just load either of them only once. Hope this helps.
Upvotes: 0
Reputation: 2557
This type of issues happen when the dependency you are passing to the module/or controller is not matching with any of the defined services.
I see you are using userService
in the function argument but, there is not definition to that, I believe you should use myFactory
instead.
app.controller('myCtrl',['$scope','myFactory',function ($scope,myFactory) {
Upvotes: 0