在 ng-repeat 中更改角度 ui-view [英] change angular ui-view inside ng-repeat

查看:26
本文介绍了在 ng-repeat 中更改角度 ui-view的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个控制器中使用了多个命名的 ui-view.使用以下代码在 html 文件中命名 ui-view 时,一切都按预期工作:

<div ui-view="选择器"></div><div ui-view="widget1"></div><div ui-view="widget2"></div><div ui-view="widget3"></div><div ui-view="widget4"></div>

但是当我想用 ng-repeat 动态加载其中一些视图时,它不会更新信息.

<div class="widget-container" ng-repeat="widget in widgets"><div ui-view="{{widget}}"></div>

如何从我的 ng-repeat 加载 ui-views?

解决方案

这个问题还没有得到解答,所以我决定继续展示如何去做.不幸的是,由于某种原因,问题中的尝试没有奏效,但您可以做的是链接到大括号之间的函数并返回所需视图的字符串.例如控制器看起来像这样:

$scope.groups = ['main','cases','models'];$scope.pickView = 函数(索引){返回 $scope.groups[index];};

I am using multiple named ui-views in a single controller. Everything is working as spected when name the ui-view in the html file with this code:

<div class="box"> 
  <div ui-view="selector"></div>  

  <div ui-view="widget1"></div>
  <div ui-view="widget2"></div>
  <div ui-view="widget3"></div>
  <div ui-view="widget4"></div>
</div>

But when I want to load dynamically some of those views with a ng-repeat it does not update the information.

<div class="widgets">
  <div class="widget-container" ng-repeat="widget in widgets">
    <div ui-view="{{widget}}"></div>
  </div>
</div>

How could I load ui-views from my ng-repeat?

解决方案

This hadn't been answered so i decided to go ahead and show how to do it. Unfortunately for some reason the attempt in the question didn't work but what you can do is link to a function between curly brackets and return the string of the view you want. For instance the controller would look like this:

$scope.groups = ['main','cases', 'models']; $scope.pickView = function(index){ return $scope.groups[index]; };

这篇关于在 ng-repeat 中更改角度 ui-view的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆