RudziankoŇ≠ RudziankoŇ≠ - 3 months ago 15
AngularJS Question

AngularJS: NameError: name is not defined

I get error:

NameError: name 'resp' is not defined


While rendering this
html


<html lang="en">
<head>
<meta charset="UTF-8">
<title>SPA book_store</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script> src = "main.js"</script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input id="filter_input" type="text" ng-model="word"/>
<br/>
<input id="btn" type="button" ng-click="get()" value="Check Level">
<br/>
<label>{{resp}}</label>
</div>
<br/>

</body>
</html>


main.js in the same directory with
html
file:

var app = angular.module('myApp', []);

app.controller('myCtrl', function ($scope, $http) {
$scope.resp= {};
$scope.get = function() {
$http.get("https://localhost/" + $scope.word)
.then(function (response) {
$scope.resp = response.data;
});
}
});


I defined
resp
in controller as scope variable. What am I doing wrong?

Answer

It's the mistake I guess. Change this

<script> src = "main.js"</script>

to

<script src="main.js"></script>