我刚开始使用 AngularJS。我添加了一个视图/控制器和路线,一切正常。但是,一旦我开始使用不同的控制器添加另一条路线,事情就无法正常工作。以下是我的代码,
<!doctype html>
<html ng-app='simpleApp'>
<body>
<div data-ng-view=""></div>
<script src="js/angular.js"></script>
<script>
var sampleModule = angular.module('simpleApp', []);
var controllers = {};
controllers.SimpleController = function($scope){
$scope.books = [ {title: "The book thief", author:"Unknown"},
{title:"Da Vinci Code", author:"Dan Brown"},
{title:"Gamperaliya", author:"Martin Wickremasinghe"}
];
$scope.addTitle = function()
{
$scope.books.push({title:$scope.newTitle, author:$scope.newAuthor} );
}
$scope.removeTitle = function()
{
$scope.books.pop({title:$scope.newTitle, author:$scope.newAuthor} );
}
}
controllers.detailController = function ($scope)
{
$scope.abc = 'sdsdsd';
$scope.titleDetail = $location.search.title;
alert('dfdfd');
}
sampleModule.controller(controllers);
sampleModule.config(function($routeProvider) {
$routeProvider
.when('/',
{
controller: 'SimpleController',
templateUrl: 'third1.html'
})
.when('/detail/title/:titleId',
{
controller: 'detailController',
templateUrl: 'third2.html'
})
.otherwise( {redirectTo: '/' });
});
</script>
third1.html 成功加载,它有一个加载 third2.html 的链接,我希望它提供有关这本书的更多详细信息。但是在third2.html 中,我无法从detailController 或URL 中获取值。它不评估 {{ }} 指令。
有什么帮助吗?
伊什