0

控制器:

'use strict'

angular.module('browse', [])

    .controller('browseCtrl', ['$scope', 'exchangesFctr', function($scope, exchangesFctr) {

        // exchanges
        $scope.exchanges = exchangesFctr.get();
        $scope.exchange = null;
        $scope.$watch('exchange', function() {
            console.info('EXCHANGE', $scope.exchange);
        });

        // sectors
        $scope.sector = null;
    }]);

交换部分:

<div class="btn-group" ng-controller="browseCtrl">
    <button type="button" class="btn" btn-radio="exchange" ng-model="$parent.exchange"
            ng-repeat="exchange in exchanges | orderBy:exchange.name">{{ exchange.name }}</button>
</div>
    <ng-include src="'browse/sectors.html'" />

部分行业:

<div class="btn-group" ng-controller="browseCtrl" ng-hide="$parent.exchange == null">
    <p>todo</p>
</div>

1) 使用 ui.bootstrap:为什么在交换部分需要 ng-model 绑定到父级才能工作?我希望这是ng-model="exchange"?我在这里做错了吗?

2)在部分扇区上ng-hide只执行一次。我希望表达式在$scope.exchange更改时更新。我必须使用什么表达式才能使其始终保持最新?

4

1 回答 1

1

这与 UI Bootstrap 无关。这是因为正常的 javascript 原型行为而发生的。如果您使用原始类型,那么您必须使用 $parent 否则如果您切换到对象语法,则不需要使用 $parent 请参见下面的示例代码

$scope.exchange = {name:null};

然后 html 应该是 ng-model="exchange.name" (如果你想要对象而不是原语,则无需使用父级)

该网址将向您详细解释所有内容https://github.com/angular/angular.js/wiki/Understanding-Scopes

于 2013-07-05T10:58:00.320 回答