【发布时间】:2015-07-05 10:20:27
【问题描述】:
我有一个页面,其中包含带有页面显示内容的pageNavigator。根据用户click 在相应按钮(链接)上的说法,我正在更新页面。
我将 :page navigator 的指令设为“docNavigation”并包含在我的home html 中。
现在我要求,
当页面加载时,
-
我的文档页面应该显示
count,就像我在homeController中提到的一样,最后一个switch应该设置为20,我在homeController中设置。 当用户交互时,我想更新
homeController中的count以更新页面内容。
得到这个的正确方法是什么?
这是我的指令:
"use strict";
angular.module("docNaviDir", [])
.directive("docNavigation", function () {
return {
restrict : "E",
replace : true,
templateUrl : '/views/directiveViews/docNavigation.html',
link : function (scope, element, attr, controller) {
var count = 0;
element.find('a').on('click', function () {
var Id = $(this).prop('id');
switch(Id) {
case 'first':
count = 1; //update to `homeController`
break;
case 'prev':
count -= 1; //update to `homeController`
break;
case 'next':
count += 1; //update to `homeController`
break;
case 'last':
count = scope.totalPages; //get from `homeController`
break;
}
scope.$apply(function () {
count = count;
})
})
}
}
})
我的家庭控制器:
“用户严格”;
angular.module("ngTenderDocument")
.controller('homeController', function ($scope) {
$scope.count = 0; //pass to directive and update by user
$scope.totalPages = 20; //pass to directive
})
我的观点:
<doc-navigation></doc-navigation> //directive
<h1>This is from home! Now you start to count, count is : {{count}}</h1> //count need to show the appropriate updates here.
我的导航视图:
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav">
<li class="active"><a id="first" href="#">First</a></li>
<li><a id="prev" href="#">Previous</a></li>
<li><a id="next" href="#">Next</a></li>
<li><a id="last" href="#">Last</a></li>
</ul>
</nav>
【问题讨论】:
-
我假设 HomeController 将始终在屏幕上?
-
不,这仅适用于
home.html视情况而定。 -
让我重新表述我的问题:导航栏是否总是在 HomeController 可用的屏幕上使用?如果没有,您打算如何在其他屏幕上实现此分页?
-
其实这是主屏幕的一个子屏幕。这个屏幕只有
pagenavigation更新了html 内容。 (这个页面本身就是另一个页面的内容)
标签: jquery angularjs angularjs-scope angular-directive