AngularJS:NameError:未定义名称

时间:2016-08-26 13:44:40

标签: javascript angularjs

我收到错误:

NameError: name 'resp' is not defined

渲染此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与html文件在同一目录中:

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;
                });
    }
});

我在控制器中将resp定义为范围变量。我究竟做错了什么?

1 个答案:

答案 0 :(得分:3)

这是我猜的错误。改变这个

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

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