1

ディレクティブを書くとき、javascript に (時にはたくさんの) html コードを書くことになります。

javascriptfiles に xml を含めるのは好きではありません。テンプレートは非常に複雑になる可能性があり、ほとんどのマークアップ エンジンはテンプレートを 1 色でレンダリングするため、' と + を使用する必要があります。HTML と JavaScript を分離するための良い方法はありますか。

これがどのように見えるかのサンプルです:

angular.module('ballentines', ['ngStorage']).
directive('fineUploader', function() {
    return {
        restrict: 'A',
        scope: {},
        require: '?ngModel',
        link: function($scope, element, attributes, ngModel) {
            $scope.uploader = new qq.s3.FineUploader({
                debug: true,
                element: element[0],
                request: {
                    endpoint: 'endpoint',
                    accessKey: 'accesskey'
                },
                signature: {
                    endpoint: '/s3/'
                },
                iframeSupport: {
                    localBlankPagePath: '/success.html'
                },
                retry: {
                    enableAuto: true // defaults to false
                },
                text: {
                    uploadButton: '<p>Upload File</p>'
                },
                template:
                    '<div class="qq-uploader">' +
                        '<p class="qq-upload-drop-area">{dragZoneText}</span></p>' +
                        '<div class="qq-upload-button btn btn-info">{uploadButtonText}</div>' +
                        '<span class="qq-drop-processing">{dropProcessingText}</span>' +
                        '<ul class="qq-upload-list" ></ul>' +
                    '</div>',
            });
        }
    };

})
4

3 に答える 3

0

他の人は、HTMl をテンプレートに入れ、templateURL を使用してコードをリンクする方が簡単だと述べています。

追加したいのは、テストの作成を開始したら、作業を容易にするために、いくつかのテンプレート サービスを検討する必要があるということです。

私は角度のあるプロジェクトのほとんどでうなり声を使用しているので、これが最終的に使用したものです。

https://npmjs.org/package/grunt-angular-templates

于 2013-10-28T17:03:52.447 に答える