Angular控制器在索引页面中运行良好,但是当我从链接页面调用它们时,它们无法正常工作。我需要对控制器做什么才能处理页面?
我的索引页面已定义应用程序。
<script type="text/javascript" src="js/controller/MyAboutPageController.js"></script>
<div class="navbar">
<div class="navbar-inner">
<div class="left">
<a href="#" class="back link">
<i class="icon icon-back"></i>
<span>Back</span>
</a>
</div>
<div class="center sliding">About</div>
<div class="right">
<a href="#" class="link icon-only open-panel"><i class="icon icon-bars"></i></a>
</div>
</div>
</div>
<div class="pages">
<div data-page="about" class="page">
<div class="page-content">
<div class="content-block" ng-controller="MyAboutPageController">
<p>Here is About page!</p>
{{name}}
</div>
</div>
</div>
</div>
我已将外部网页链接为:
MyApp.angular.controller(
关于页面我有:
MyApp.controller(
我尝试使用<script type="text/javascript" src="js/controller/MyAboutPageController.js"></script>
和MyAboutPageController
,两者都不起作用。此外,我在索引和关于页面中包含 MyApp.angular.controller("MyAboutPageController", function($scope){
$scope.name = "John Wick Test";
console.log("MyAboutPageController loaded fine!!");
});
并且没有帮助。
namespace platform {
struct event {};
struct keyboard_event : public event {};
const platform::event& wait_event()
{
return platform::keyboard_event();
}
}
int main(int argc, const char* argv[])
{
const platform::event& event = platform::wait_event();
return 0;
}
:
main.cc:7:12: warning: returning reference to local temporary object [-Wreturn-stack-address]
return platform::keyboard_event();
^~~~~~~~~~~~~~~~~~~~~~~~~~
关于页面加载正常,但控制器不。请帮忙。
答案 0 :(得分:0)
Angular旨在帮助您创建SPA(单页应用程序),这意味着您无需在页面之间导航(无回发,无新页面)。
我建议您使用ng-view和$ routeProvider,如下所示:
<head>
...
<script src="scripts/app/index.js"></script>
</head>
然后在你体内:
<body ng-app="YourApp">
...
Click <a href="#!about">here</a> to go to About
<div ng-view></div>
你的index.js中的:
app.config(function ($routeProvider) {
$routeProvider
.when('about', {
templateUrl: 'Views/about.html',
controller: 'AboutController'
})
...
app.controller("AboutController", function($scope){
$scope.name = "John Wick Test";
console.log("MyAboutPageController loaded fine!!");
});