ng中的AngularJS if/else重复

ng中的AngularJS if/else重复,angularjs,angularjs-scope,Angularjs,Angularjs Scope,我有这个 controller: "photogridCtrl", templateUrl: 'js/ng-assets/templates/directives/photogrid-view.html', scope: '=info' 在我的控制器中,我有2个 $scope.home = [ { img: 'img/burlington.jpg', label: 'Burlington', action: '#/',

我有这个

controller: "photogridCtrl",
templateUrl: 'js/ng-assets/templates/directives/photogrid-view.html',
scope: '=info'
在我的控制器中,我有2个

$scope.home = [
    {
        img: 'img/burlington.jpg', 
        label: 'Burlington', 
        action: '#/', 
        row:'col-md-12', 
        class:''
    }
另一个是

$scope.featured = [
    {
        img: 'img/kitchener.jpg', 
        label: 'Kitchener', 
        action: '#/', 
        row:'col-md-12', 
        class:''
    }
在我看来

<div class="photo-grids">
    <div class="row">
        <div class='{{item.row}} margin-bottom' ng-repeat='item in home'>
        <a href="{{item.action}}" class="photo-item {{item.class}}" style="background-image:url({{item.img}});">
        <span class="photo-caption"><h4>{{item.label}}
        <br><small>Ontario</small></h4></span>
        </a>
    </div>
</div>

在我的主索引中,我有两个页面,我想在其中显示photogrid-view.html

<photogrid-view></photogrid-view>

<photogrid-view info='featured'></photogrid-view>

现在,正如您在我的ng repeat中所看到的,我有
“item in home”
我只想问一下如何将
home
更改为根据

鉴于:

<div class='{{item.row}} margin-bottom' ng-repeat='item in returnArray()'>

或:


或者就在眼前:

<div ng-show="info" class='{{item.row}} margin-bottom' ng-repeat='item in featured'>
<div ng-hide="info" class='{{item.row}} margin-bottom' ng-repeat='item in home'>

鉴于:

<div class='{{item.row}} margin-bottom' ng-repeat='item in returnArray()'>

或:


或者就在眼前:

<div ng-show="info" class='{{item.row}} margin-bottom' ng-repeat='item in featured'>
<div ng-hide="info" class='{{item.row}} margin-bottom' ng-repeat='item in home'>


这可以通过
ng(如果
)轻松实现。在我看来,这比
ng show
要好,因为这只在满足条件的情况下将其附加到DOM中,而
ng show
只是将其隐藏。




这可以通过
ng(如果
)轻松实现。在我看来,这比
ng show
要好,因为这仅在满足条件的情况下将其附加到DOM中,而
ng show
只是将其隐藏。

如果使用隔离作用域,可以使用ng repeat=“item In info”并从外部像以前一样设置信息。或者控制器是组件/指令的控制器?如何从信息中获取值?我以前没有见过您使用的语法,但看起来您使用的是指令。如果您使用作用域:{info:'='},并且$scope.myArray的值将自动绑定到指令的隔离作用域。如果您使用隔离作用域,则可以使用ng repeat=“item in info”并像前面一样从外部设置信息。或者控制器是组件/指令的控制器?如何从信息中获取值?我以前没有见过您使用的语法,但看起来您使用的是指令。如果使用scope:{info:'='},并且$scope.myArray的值自动绑定到指令的独立作用域。您不能使用ngRepeat在函数上迭代,请参见此。另外,
ng init
不监视更改,因此结果列表不会更新。所以前3个例子是不正确的。我如何从中获得信息的价值?如果info==featured,那么返回$scope.featured?我很抱歉这个函数,@koiiey你是对的,它对原始值不起作用,但对于变量,它起作用。所谓更改,我指的是更改列表。@jeeee,在您的示例中,“info”是范围变量,如果您愿意(实际上,您希望:),您可以删除第二个ng REPLAT div,并像视图中的下一个一样删除ng REPLAT use,其中“特色”-范围中的数组,$scope.featured:)和yep,我和Mikey忘了关闭div标记:DYou不能使用ngRepeat迭代函数,请参见此。另外,
ng init
不监视更改,因此结果列表不会更新。所以前3个例子是不正确的。我如何从中获得信息的价值?如果info==featured,那么返回$scope.featured?我很抱歉这个函数,@koiiey你是对的,它对原始值不起作用,但对于变量,它起作用。所谓更改,我指的是更改列表。@jeeee,在您的示例中,“info”是范围变量,如果您愿意(实际上,您希望:),您可以删除第二个ng REPLAT div,并像视图中的下一个一样删除ng REPLAT use,其中“特色”-范围中的数组,$scope.featured:)和yep,我和Mikey忘了关闭div标签:没有他的代码我无法正常工作对不起:(但是谢谢!:)没有他的密码我无法工作。对不起(但是谢谢!)
<div ng-if="info === 'featured'" class='{{item.row}} margin-bottom' ng-repeat='item in featured'></div>
<div ng-if="info === 'home'" class='{{item.row}} margin-bottom' ng-repeat='item in home'></div>