我有一个 list.html 页面,如下所示:
<table class="table table-striped table-condensed table-hover">
<tr>
<th>Artist</th>
<th>Title</th>
<th>Genre</th>
<th>YouTube URL</th>
<th>IMG URL</th>
<th>Owner</th>
<th>Created</th>
<th>Rating</th>
</tr>
<tr>
<td>{{test}}</td>
</tr>
<!--<tr ng-repeat="track in tracks">
<td>{{track.Artist}}</td>
<td>{{track.Title}}</td>
<td>{{track.Genre}}</td>
<th>{{track.URL}}</th>
<th>{{track.imgURL}}</th>
<th>{{track.Owner}}</th>
<th>{{track.Created}}</th>
<th>{{track.rating}}</th>
<td>{{scope.hey}}</td>
</tr>-->
</table>
list.html是一个放入ng-view的视图模板。
这是我的app.js:
'use strict';
var app = angular
.module('SurfApp', ['ngCookies', 'ngResource', 'ngSanitize', 'ngRoute'])
.config(function ($routeProvider) {
$routeProvider.
when('/', { templateUrl: 'list.html', controller: 'ListCtrl' }).
otherwise({ redirectTo: '/' });
});
SurfApp.factory('TrackGet', function ($resource) {
return $resource('/api/track/:id', { id: '@id' }, { update: { method: 'PUT' } });
});
var ListCtrl = function ($scope, $location, TrackGet) {
$scope.test = "hello";
};
好的,所以我不确定为什么这不起作用。当我查看index.html(反过来,将list.html加载到ng-view中)时,我只看到{{test}},而不是看到&#34; hello&#34;的$ scope.test值。 / p>
我知道我的工厂代码导致错误,因为如果我注释掉整个SurfApp.factory代码块,并且还删除了&#34; TrackGet&#34;从ListCtrl控制器注入,我会正确地看到&#34;你好&#34;而不是&#34; {{test}}&#34;在index.html。
我正在按照指南来做这件事,真的很困惑为什么它不适合我,但它对作者起作用了(它也是一个视频指南,所以我一直在看他编码并让它实时工作。)
如果这有任何用处,请点击我的index.html:
<!DOCTYPE html>
<html>
<head>
<title>SurfM</title>
<link rel="stylesheet" type="text/css" href="Content/bootstrap.css" />
</head>
<body ng-app="SurfApp">
<div class="container">
<div ng-view></div>
</div>
<script src="Scripts/jquery-1.10.2.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/bootstrap.js"></script>
<script src="Scripts/angular-resource.js"></script>
<script src="Scripts/angular-cookies.js"></script>
<script src="Scripts/angular-sanitize.js"></script>
<script src="Scripts/angular-route.js"></script>
<script src="Scripts/app.js"></script>
</body>
</html>
感谢您对此问题的任何提示或见解! :)