【发布时间】:2017-02-17 14:27:19
【问题描述】:
大家好,我遇到了 Angular 项目的问题。我的项目是一个 HTML 页面,我在 head 标签中有以下 JS 代码:
var app = angular.module('App', []);
app.controller = ('Data', function ($scope, $http) {
$http.get('http://www.omdbapi.com/?s=' + my_var).success(function (response) {
$scope.Movies = response.Search;
});
});
我的相关内容如下:
<body ng-app="App">
...
<table id="search-results-container" ng-controller="Data">
<tr>
<td>
<img src="{{fetched.Poster}}" alt="" />
</td>
<td>
<div class="result-content">
<a href="#" onclick="return false;" class="movie-title"><h2>{{fetched.Title}}</h2></a>
<label>Year: {{fetched.Year}}</label>
</div>
</td>
</tr>
</table>
我在 Inspect Element 控制台收到以下错误:
错误 1:
GET file:///C:/Users/user/path_to_page/%7B%7Bfetched.Poster%7D%7D net::ERR_FILE_NOT_FOUND
错误 2:
Error: [ng:areq] http://errors.angularjs.org/1.5.6/ng/areq?p0=Data&p1=not%20a%20function%2C%20got%20undefined
at angular.js:38
at sb (angular.js:1911)
at Qa (angular.js:1921)
at angular.js:10153
at $f (angular.js:9272)
at n (angular.js:9065)
at g (angular.js:8459)
at g (angular.js:8462)
at g (angular.js:8462)
at g (angular.js:8462)
我是 AngularJS 的新手,我不知道我在做什么,我已经在谷歌上搜索了 2 天...感谢任何帮助,谢谢
【问题讨论】:
-
试试
app.controller('Data', function ($scope, $http) {而不是app.controller = ('Data', function ($scope, $http) { -
哇,谢谢@dan,做了一些技巧,但现在我的数据返回空白... json 文件具有以下格式:omdbapi.com/?s=starwars 我尝试将其设置为
$scope.Movies = response而不是 @987654330 @ 但这也没有用。非常感谢你的帮助,谢谢 -
哦,第一个错误仍然存在我不明白为什么它试图从我的计算机中获取名称为
{{fetched.Poster}}的文件 -
没问题。我添加了一个我认为可以解决一些问题的答案。
标签: javascript html angularjs arrays json