我使用AngularJS和MVC 5的版本1.2.2,我有从获取执行让我的服务代码的问题。角服务不会被调用
这里是我在我的_Layout.cshtml文件链接
div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home", null, new { @class = "navbar-brand" })</li>
<li>@Html.ActionLink("Albums", "Index", "Album")</li>
</ul>
</div>
我的模块看起来像这样
var app = angular.module('myApp', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider
.when('/Home',
{
controller: 'HomeController',
templateUrl: '/Views/Home/Index.cshtml'
})
.when('/Album',
{
controller: 'AlbumController',
templateUrl: '/View/Album/Index.cshtml'
})
.otherwise({ redirectTo: '/Home' });
});
我AlbumController
看起来像这样
app.controller('AlbumController', function ($scope, albumService) {
init();
function init() {
$scope.albums = albumService.getAlbums();
}
});
我albumService
看起来是这样的
app.service('albumService', function() {
this.getAlbums = function() {
return albums;
};
var albums = [
{
id: 1, Name: 'Foo', AlbumNumber: 1,
Songs: [
{ Id: 1, Name: 'Bar', AlbumId: 1, TrackNumber: 1 }
]
}
];
});
我View/Album/Index.cshtml
看起来是这样的:
{{album.Name}}
的问题是,专辑名不显示在页面上。我究竟做错了什么?
编辑
我的NG-程序指令是在我_Layout.cshtml文件。
<html data-ng-app="myApp">
哪里是你的NG-应用程序的指令? – billb
即将更新文本。 –
如果您查看源文件,您是否看到包含角文字?由于上面的代码片段中没有它们,因此尚不清楚。 – billb