5

これが私のコードです

'use strict';
angular.module('app')
    .directive('item'
            , ["$timeout"
            , "$Service"
            , function(
                $timeout
                , $utils) {
    return {
        restrict: 'A',
        scope: {
            item: '=',
        },
        transclude: true,
        link: function(scope, element, attrs, ctrl, transclude){
        },
        templateUrl: $fsUtils.getRelativeUrl('templates/item.html'),
        controller: 'ItemCtrl', 
    };
}]);

私のindex.html:

<item><div>Transcluded content.</div></item>

transclude 変数はundefinedで、ctrl 変数はproto__: Objectです。親スコープをトランスクルージョンされたスコープに挿入する必要があります。トランスクルード変数は未定義です。どこが間違っているのですか。

私のAngularバージョンは1.1.5です

ありがとう。

4

1 に答える 1

0

あなたが探しているのは、transcludeFn です。これを試して:

transclude: true,
transcludeFn: function () { /*do your stuff here*/ },
...
link: function(scope, element, attrs, controller, transcludeFn)

リンク関数でコントローラーにアクセスするには、次のようにします。

var controller = scope.controller;
于 2015-07-01T08:22:18.193 に答える