0

最近、1.4 にアップグレードしましたが、このホバー ディレクティブの動作に問題があります。

以前は動作していたコード:

angular
    .module('tagHoverDirective', []).controller('TagsHover', TagsHover)
    .directive('tagsHover', directive);

function directive () {
    var directive = {
        templateUrl : "popovers/tagsPopovers/tagsHover.html",
        restrict: "E",
        replace: true,
        bindToController: true,
        controller: TagsHover
        link: link,
        scope: {
            tag:'=ngModel'
        }
    };
    return directive;
    function link(scope, element, attrs) {}
}

TagsHover.$inject = [
    '$scope',
    '$timeout'];

function TagsHover(
    $scope,
    $timeout) {
    ....

1.4 では を使用する必要があり、この部分を次Controller as syntaxのように変更する必要がありました。function directive ()

function directive () {
    var directive = {
        templateUrl : "popovers/tagsPopovers/tagsHover.html",
        restrict: "E",
        replace: true,
        bindToController: true,
        controller: 'TagsHover as tgh',
        link: link,
        scope: {
            tag:'=ngModel'
        }
    };
    return directive;
    function link(scope, element, attrs) {}
}

ng-showマークアップの が機能しなくなりましたが、どうすれば修正できますか? tghorは使用していませんthis。実際には、tagこのディレクティブに渡されるオブジェクトを使用して可視性を設定しています。

<div class="tags-hover-container" ng-show="tag.tagsHoverDisplay">
4

1 に答える 1

2

実際に controllerAs を公開すると、「as」部分をスコープにバインドします。

したがって、$scope.anything は "as".anything になります。

コントローラーを次のように公開しています

controller: 'TagsHover as tgh',

これは、$scope/this をオブジェクト tgh にバインドしていることを意味します。したがって、scope.tag は tgh.tag になります。

テンプレートは次のようになります

<div class="tags-hover-container" ng-show="tgh.tag.tagsHoverDisplay">
于 2015-06-29T19:04:06.180 に答える