我想使用父列表的索引(foos)作为子列表(foos.bars)中函数调用的参数.
我找到了一个帖子,有人建议使用$ parent.$ index,但$index不是属性$parent.
如何访问父级索引ng-repeat?
<div ng-repeat="f in foos">
<div>
<div ng-repeat="b in foos.bars">
<a ng-click="addSomething($parent.$index)">Add Something</a>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 以前有人问过,从答案看起来并不好看.我想考虑一下这个示例代码......
我的应用程序加载提供它的服务中的当前项.有几个控制器可以在不重新加载项目的情况下操纵项目数据.
如果尚未设置,我的控制器将重新加载项目,否则,它将使用服务器之间,控制器之间当前加载的项目.
问题:我想为每个控制器使用不同的路径而不重新加载Item.html.
1)这可能吗?
2)如果那是不可能的,那么每个控制器的路径是否比我在这里提出的更好?
app.js
var app = angular.module('myModule', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/items', {templateUrl: 'partials/items.html', controller: ItemsCtrl}).
when('/items/:itemId/foo', {templateUrl: 'partials/item.html', controller: ItemFooCtrl}).
when('/items/:itemId/bar', {templateUrl: 'partials/item.html', controller: ItemBarCtrl}).
otherwise({redirectTo: '/items'});
}]);
Run Code Online (Sandbox Code Playgroud)
Item.html
<!-- Menu -->
<a id="fooTab" my-active-directive="view.name" href="#/item/{{item.id}}/foo">Foo</a>
<a id="barTab" my-active-directive="view.name" href="#/item/{{item.id}}/bar">Bar</a>
<!-- Content -->
<div class="content" ng-include="" src="view.template"></div>
Run Code Online (Sandbox Code Playgroud)
controller.js
// Helper function to load $scope.item if refresh or directly linked
function itemCtrlInit($scope, $routeParams, MyService) {
$scope.item = MyService.currentItem;
if (!$scope.item) {
MyService.currentItem = MyService.get({itemId: …Run Code Online (Sandbox Code Playgroud) 我limitTo在docs中看到了过滤器,它允许我限制前5个或最后5个结果,但我想设置我的限制开始的位置,所以我可以显示第二组5个结果.
是否有内置的过滤器?
我正在使用AngularJS作为前端JS库,在Revel框架中使用Go模板来生成后端的标记.
但无论你去角的使用{{,并}}在他们的模板分隔符.如何在Go中将它们传递给AngularJS?
目标:使用指令在两个兄弟元素之间进行通信来创建行为(每个元素都有自己的指令).
在示例中使用的行为:默认情况下隐藏文章内容.单击标题时,我希望显示相关的文章内容.
catch:相关的article元素需要彼此关联,而不是嵌套在单个父元素或指令中.
<div article="article1">this is my header</div>
<div id="article1" article-content>this is content for the header above</div>
<div article="article2">this is my header</div>
<div id="article2" article-content>this is content for the header above</div>
Run Code Online (Sandbox Code Playgroud)
我知道将内容放在article指令中更容易,但是这个问题是要找出如何解决这样的情况.
内容指令能否以某种方式将自身传递给相关的文章指令?
这段代码现在不是很有用,但它是一个起点.我怎么做到这一点?
.directive('article', function(){
return {
restrict: "A",
controller: function($scope) {
$scope.contentElement = null;
this.setContentElement = function(element) {
$scope.contentElement = element;
}
},
link: function(scope, element) {
element.bind('click', function(){
// Show article-content directives that belong
// to this instance (article1) of the directive
}
}
}
}
.directive('articleContent', …Run Code Online (Sandbox Code Playgroud) 我知道你不应该把你的显示逻辑放在一个控制器中,我正在努力用正确的AngularJS方法来解决这个问题.
我在模态中呈现形式.我正在使用Zurb Foundation的模型显示.
标记:
<div class="button" ng-click="modalAddWidget">Add Widget</div>
<div id="modalAddWidget" class="reveal-modal">
<h6>New Widget</h6>
<form>
<fieldset>
<legend>Widget Name</legend>
<input type="text" ng-model="ui.add_widget_value" />
</fieldset>
<div class="small button right" ng-click="addWidget()">Add Widget</div>
<div class="small button right secondary" ng-click="addWidgetCancel()">Cancel</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
...
$scope.modalAddWidget = function() {
$("#modalAddWidget").reveal();
}
$scope.addWidget = function() {
$scope.myobject.widgets.push({"name": $scope.ui.add_widget_value});
$scope.ui.add_widget_value = '';
$('#modalAddWidget').trigger('reveal:close');
}
$scope.addBudgetCancel = function() {
$scope.ui.add_widget_value = '';
$('#modalAddWidget').trigger('reveal:close');
}
...
Run Code Online (Sandbox Code Playgroud)
注意:$ scope.ui是我用来存储不应绑定到我的对象的UI值的对象,直到用户实际点击"添加窗口小部件"为止
$ scope.myobj是我的数据存储位置.
Foundation的$("#modalAddWidget").reveal();功能提供了模态叠加.
因为我不应该将我的显示代码放在控制器中,所以采用这种方法的正确方法是什么?
我正在尝试创建一个只更新系统上文件的软件包,但是在运行rpmbuild时我一直遇到错误.该错误表示文件丢失.
我在CentOS 5和6上尝试过这个,结果相同.
我曾经rpmdev-setuptree设置过文件系统,也就是设置~/.rpmmacros文件.然后我用来rpmdev-newspec初始化spec文件.
我作为非root用户运行.
我有spec文件~/rpmbuild/SPECS/test.spec,我的来源是:~/rpmbuild/SOURCES/test-1.tar.gz.提取此文件会创建一个以test-12个文件命名的目录.我已经确认~/rpmbuild/BUILD/test-1在我尝试构建软件包时它会被提取出来.
我跑: rpmbuild -ba ~/rpmbuild/SPECS/test.spec
然后我收到这个错误:
- ./configure --build = x86_64-redhat-linux-gnu --host = x86_64-redhat-linux-gnu --target = x86_64-redhat-linux-gnu --program-prefix = --prefix =/usr - exec-prefix =/usr --bindir =/usr/bin --sbindir =/usr/sbin --sysconfdir =/etc --datadir =/usr/share --includedir =/usr/include --libdir =/usr/lib64 --libexecdir =/usr/libexec --localstatedir =/var --sharedstatedir =/usr/com --mandir =/usr/share/man --infodir =/usr/share/info/home/me/rpmbuild /tmp/rpm-tmp.58942:line 37:./ configure:没有这样的文件或目录错误:/home/me/rpmbuild/tmp/rpm-tmp.58942(%build)的退出状态错误
RPM构建错误:/home/me/rpmbuild/tmp/rpm-tmp.58942(%build)的退出状态错误
这是我的spec文件:
Name: test
Version: 1
Release: 1%{?dist}
Summary: Test
Group: Test
License: …Run Code Online (Sandbox Code Playgroud) 我很难找到如何从路由访问REST客户端的IP地址.
server.get('api/foo', function(req, res, next) {
// How can I access the IP address of the requester from here?
}
Run Code Online (Sandbox Code Playgroud) 我有一个相当昂贵的服务器调用,我需要缓存30秒.然而,似乎我无法使缓存过期.
在下面的代码中,在第一次缓存之后,即使在time()+ 30秒之后,它也永远不会超过$ return-> cache_data.
注意,我甚至可以打印$ cache-> expire,它肯定设置为30秒前的时间,永远不会更新.
我已多次手动清除缓存以确认我得到相同的结果.
这有什么不妥吗?
function mymodule_get_something($id) {
// set the unique cache id
$cid = 'id-'. $id;
// return data if there's an un-expired cache entry
// *** $cache ALWAYS gets populated with my expired data
if ($cache = cache_get($cid, 'cache_mymodule')) {
return $cache->data;
}
// set my super expensive data call here
$something = array('Double Decker Taco', 'Burrito Supreme');
// set the cache to expire in 30 seconds
cache_set($cid, $something, 'cache_mymodule', time() + …Run Code Online (Sandbox Code Playgroud) 我需要一些关于如何调试挂起的新服务器配置的提示.这个站点本身就是Drupal的一个非常大的例子.与每页加载45+ MB的PHP内存一样大,具有APC功能.
该站点本身使用nginx/php-fpm/apc在另一台服务器上运行.我正在设置的新服务器有一个自定义的PHP 5.3版本.
nginx配置为侦听端口80,并将fastcgi请求传递给127.0.0.1:9000.这有效.
在Drupal根目录中,我有一个带有phpinfo()的普通PHP文件; 在里面.我可以直接加载这个PHP文件并确认PHP构建看起来不错.
没有nginx错误,但是php-fpm错误日志会在页面挂起时显示:
[2012年12月22日17:41:16]警告:[pool www] child 19760,脚本'/var/www/mysite/public_html/index.php'(请求:"GET /index.php")执行速度太慢(5.068781秒),记录
除了这个错误,没有什么.
考虑到正常的PHP脚本加载正常,我正在寻找有关调试方法的建议,但加载Drupal应用程序(直接到index.php,甚至不尝试干净的URL)都会挂起.