當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript app.directive函數代碼示例

本文整理匯總了TypeScript中app.directive函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript directive函數的具體用法?TypeScript directive怎麽用?TypeScript directive使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了directive函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

// Created by baihuibo on 16/3/30.
import app from "app";

/**
 * @examples
 *  <iframe frame-src="{{T.src}}"></iframe>
 *
 *  class TestCtrl{
 *    public src:string = '';
 *
 *    constructor(){
 *      this.src = 'http://host/to/path/to/file'
 *    }
 *  }
 */
app.directive('frameSrc', function () {
    return function (scope, iframe, attr) {
        if (iframe.is('iframe')) {
            attr.$observe('iframeSrc', function (val) {
                iframe.attr('src', val || 'about:blank');
            });
        } else {
            console.warn('not iframe tag');
        }
    }
});
開發者ID:baihuibo,項目名稱:idsp-base-web-seed,代碼行數:26,代碼來源:frame-src.ts

示例2: function

app.directive('remoteValid', function ($log) {
    var defaults = {
        method: 'get',
        check: null,
        params: {},
        invokeParam: {}
    };
    var name = "remoteValid";
    return {
        restrict: 'A',
        require: '?ngModel',
        scope: {option: '=remoteValid'},
        link: function (scope:any, el, attr, ctrl) {
            if (!ctrl)return;

            var option:RemoteValidOption = _.defaults(scope.option || {}, defaults);

            function validData(newVal) {
                option.params.value = newVal;
                option.resource[option.method](
                    option.invokeParam,
                    option.params,
                    function (data) {
                        var pass;
                        if (option.check && _.isFunction(option.check)) {
                            pass = option.check(data);
                        } else {
                            pass = !!data.result;
                        }
                        ctrl.$setValidity(name, pass);
                    }, function () {
                        ctrl.$setValidity(name, false);
                    });
                return newVal;
            }

            el.on('paste', false);

            ctrl.$parsers.push(validData);

            scope.$watch(attr.ngModel, function (newVal, oldVal) {
                if (!newVal || newVal != oldVal) {
                    ctrl.$setValidity(name, true);
                }
            });
        }
    }
});
開發者ID:baihuibo,項目名稱:idsp-base-web-seed,代碼行數:48,代碼來源:remoteValid.ts

示例3: function

app.directive("remotePaging", function () {
    /**
     * @prop total 數據總數
     * @prop totalPage 總頁數
     * @prop current 當前頁數
     * @prop limit 限製數據大小
     * @prop data 當前頁數據
     */
    interface PagingResult {
        total:number
        totalPage:number
        current:number
        limit:number
        data:any[]
    }
    
    var defaults = {
        method: 'get',
        limit: 10,
        total: 0,
        resultList: [],
        limitList: [10, 20, 30, 40, 50],
        pagingSize: 5,
        params: null,
        hideDesc: false,
        invokeParam: "paging",
        reloadAll: false
    };

    return {
        templateUrl: 'scripts/__base/directives/paging/paging.html',
        scope: {
            option: "="//配置對象 {Paging}
        },
        link: function (scope:any, el, attr) {
            var option:PagingOption = scope.option = _.defaults(scope.option || {}, defaults);
            var pagingSize = option.pagingSize;
            scope.$watch('option.pagingSize', function (newVal, oldVal) {
                if (oldVal && newVal != oldVal) {
                    pagingSize = newVal;
                    option.goToPage('first', true);
                }
            });

            var limit = option.limit;
            scope.$watch('option.limit', function (newVal, oldVal) {
                if (oldVal && newVal != oldVal) {
                    limit = newVal;
                    option.goToPage('first', true);
                }
            });

            var loading;
            //讀取對應頁麵的數據
            scope.goToPage = function (page, reload) {//to page data
                if (page < 0 || (option.totalPage && page >= option.totalPage) || (page == option.currentPage && !reload)) {
                    return;
                }

                var data = {
                    current: page,
                    limit: limit,
                    method: option.method,
                    reload: option.reloadAll || !!reload,
                    total: option.total,
                    params: angular.toJson(option.params || {})
                };
                loading = true;
                option.resource[option.method](option.invokeParam, data,
                    function (result:PagingResult) {
                        option.currentPage = result.current;
                        option.total = result.total;
                        option.totalPage = result.totalPage;
                        option.resultList = _.map(result.data || [], function (item) {
                            return new option.resource(item);
                        });
                        initPageList(option.totalPage , option.currentPage);
                        loading = false;
                    }, function () {
                        loading = false;
                    });
            };

            //監聽是否有resource資源準備就緒
            scope.$watch('option.resource', function () {
                option.resource && scope.goToPage(0, true);
            });

            //刷新數據
            option.goToPage = function (page, reload) {
                if (!option.resource || loading) return;//不要重複加載,跳出方法
                switch (page) {
                    case "first" :
                        scope.goToPage(0, reload);
                        break;
                    case "last" :
                        scope.goToPage(option.totalPage - 1, reload);
                        break;
                    default:
                        scope.goToPage(option.currentPage, reload);
//.........這裏部分代碼省略.........
開發者ID:cetrinw,項目名稱:reptile,代碼行數:101,代碼來源:paging.ts

示例4: function

// Created by baihuibo on 16/3/29.
import app from "app";

app.directive("helloWord", function () {
    return {
        link: function (scope, el, attr) {
            el.text('hello seed');
        }
    }
});
開發者ID:baihuibo,項目名稱:idsp-base-web-seed,代碼行數:10,代碼來源:HelloWord.ts


注:本文中的app.directive函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。