6

私は次のようなディレクティブを書きました:

app.directive('headersort', function () {
    return {
        restrict: 'E',
        scope: {
            sortBy: '=',
            title: '='
        },
        template: '<th>{{ title }}</th>',
        replace: true,
        link: function (scope, element, attributes) { 
            scope.sortBy = attributes.sortBy;
            scope.title = attributes.title;

        }
    };
});

そして、私はそれを次のように使用します:

<headersort sortBy="Name" title="Product">

私が欲しいのは、それ<headersort sortBy="Name" title="Product">が に置き換えられること<th>Product</th>です。しかし、次のようなエラーが表示されます。

Template must have exactly one root element. was: <th>{{ title }}</th>

しかし、ルート要素が 1 つありますよね? 私のルート要素は<th>、なぜ角度がこのエラーをスローするのですか? ルート要素の条件/定義は何ですか?

4

2 に答える 2

0

要素について言っていると思いますtable。どこかで定義しましたか?

于 2013-05-21T10:02:00.783 に答える