AngularJS_自定义控件_入门学习1

简介: 本篇博客是在学习AngularJS自定义控件的学习记录,作为一个学习示例...

A-基本架构介绍

新建一个AngularJs的项目,大概项目结构如下:

项目结构:

  大概是由:app.js,bootstrap.js,app-routes.js,config.json,common-config.json等主要文件组成。

  app.js--当做项目的起始文件吧,里面会包含:注入的其他JS模块,过滤设置,配置文件的设置等。

define(function (require, exports, module) {
    var angular = require(‘angular‘);
    var asyncLoader = require(‘angular-async-loader‘);

    require(‘angular-ui-router‘);
    require(‘angular-seagull2-common‘);
    require(‘angular-seagull2-oauth‘);
    require(‘angular-seagull2-workflow‘);
    require(‘angular-seagull2-infrastructure‘);
    require(‘angular-indentity-code‘);
    require(‘angular-seagull2-empprovider‘);
    require(‘angular-seagull2-careerdev‘);
    require(‘angular-seagull2-corporation‘);

    var app = angular.module(‘app‘, [
        ‘ui.router‘,
        ‘angular-seagull2-common‘,
        ‘angular-seagull2-workflow-oauth‘,
        ‘angular-seagull2-workflow‘,
        ‘angular-seagull2-infrastructure‘,
        ‘angular-datepicker‘,
        ‘angular-indentity-code‘,
        ‘angular-seagull2-empprovider‘,
        ‘angular-seagull2-careerdev‘,
        ‘angular-seagull2-corporation‘]);

    //常规金额:由于angular默认的金额格式如果是负数的话显示格式为(12,345.00),使用customCurrency替换成:-12,345.00
    app.filter(‘customCurrency‘, ["$filter", function ($filter)
    {
        return function (amount, currencySymbol)
        {
            var currency = $filter(‘currency‘);

            if (amount < 0)
            {
                return currency(amount, currencySymbol).replace("(", "-").replace(")", "");
            }

            return currency(amount, currencySymbol);
        };
    }]);

    //将阿拉伯数字转化为中文大写
    app.filter(‘cnuppercase‘, ["$filter", function ($filter)
    {
        return function(n)
        {
            if (n === ‘‘ || n === ‘0‘ || n === 0)
            {
                return "";
            }
            if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
            {
                return "";
            }

            var unit = "千百拾亿千百拾万千百拾元角分", str = "";
            n += "00";
            var p = n.indexOf(‘.‘);
            if (p >= 0)
                n = n.substring(0, p) + n.substr(p + 1, 2);
            unit = unit.substr(unit.length - n.length);
            for (var i = 0; i < n.length; i++)
                str += ‘零壹贰叁肆伍陆柒捌玖‘.charAt(n.charAt(i)) + unit.charAt(i);
            return str.replace(/零(千|百|拾|角)/g, "零")
                .replace(/(零)+/g, "零")
                .replace(/零(万|亿|元)/g, "$1")
                .replace(/(亿)万|壹(拾)/g, "$1$2")
                .replace(/^元零?|零分/g, "")
                .replace(/元$/g, "元整");
        };
    }]);
    ////格式化字符串
    //var template1 = "我是{0},今年{1}了";
    //var template2 = "我是{name},今年{age}了";
    //var result1 = template1.format("loogn", 22);
    //var result2 = template2.format({ name: "loogn", age: 22 });
    //两个结果都是"我是loogn,今年22了"
    String.prototype.format = function (args)
    {
        var result = this;
        if (arguments.length > 0)
        {
            if (arguments.length == 1 && typeof (args) == "object")
            {
                for (var key in args)
                {
                    if (args[key] != undefined)
                    {
                        var reg = new RegExp("({" + key + "})", "g");
                        result = result.replace(reg, args[key]);
                    }
                }
            } else
            {
                for (var i = 0; i < arguments.length; i++)
                {
                    if (arguments[i] != undefined)
                    {
                        var reg = new RegExp("({[" + i + "]})", "g");
                        result = result.replace(reg, arguments[i]);
                    }
                }
            }
        }
        return result;
    };

    var commonConfig = require(‘text!../common-config.json‘);
    var config = require(‘text!../config.json‘);
    app.config([‘configureProvider‘, function (configureProvider)
    {
        configureProvider.configure(commonConfig);
        configureProvider.configure(config);
    }]);
    asyncLoader.configure(app);
    module.exports = app;
});

bootstrap.js--理解成包管理文件,其中有包的文件地址和包的依赖关系等。

require.config({
    map: {
        ‘*‘: {
            ‘ie8css‘: ‘https://develop-cdn.sinooceangroup.com/libs/requirecss-branch-seagull2/1.1.0/ie8css.min.js‘,
            ‘css‘: ‘https://develop-cdn.sinooceangroup.com/libs/requirecss-branch-seagull2/1.1.0/css.min.js‘
        }
    },
    waitSeconds: 0,
    //配置angular的路径
    paths: {
        ‘angular‘: ‘https://develop-cdn.sinooceangroup.com/libs/angular/1.2.27/angular.min‘,
        ‘angular-cookies‘: ‘https://develop-cdn.sinooceangroup.com/libs/angular/1.2.27/angular-cookies.min‘
    },
    //这个配置是你在引入依赖的时候的包名
    shim: {
        ‘text‘: { exports: ‘text‘ },
        ‘angular‘: { exports: ‘angular‘ },
        ‘angular-cookies‘: { exports: ‘angular-cookies‘, deps: [‘angular‘] },
        ‘angular-ui-router‘: { deps: [‘angular‘] },
        ‘angular-ui-tree‘: { deps: [‘angular‘, ‘css!https://develop-cdn.sinooceangroup.com/libs/angular-ui-tree/2.15.0/dist/angular-ui-tree.min‘] },
        ‘angular-datepicker‘: { deps: [‘angular‘, ‘css!https://develop-cdn.sinooceangroup.com/libs/datepicker-branch-seagull2/1.0.5/datepicker-branch-seagull2‘] },
        ‘angular-seagull2-common‘: {
            deps: [
                ‘angular‘,
                ‘urijs/uri‘,
                ‘angular-ui-tree‘,
                ‘css!https://develop-cdn.sinooceangroup.com/libs/angular-seagull2-common/1.2.1/angular-seagull2-common‘,
                ‘ie8css!https://develop-cdn.sinooceangroup.com/libs/angular-seagull2-common/1.2.1/angular-seagull2-common.ie8‘]
        }
    }
});

require([‘angular‘, ‘webuploader‘,
    ‘./javascript/app-routes‘],
    function (angular, webuploader) {
        angular.element(document).ready(function () {
            angular.bootstrap(document, [‘app‘]);
            angular.element(document).find(‘html‘).addClass(‘ng-app‘);
        });
        window.WebUploader = webuploader;
    });

app-routes.js--理解为路由器,是配置页面,JS控制器管理,及参数传递及登录验证等的地方。

define(function (require)
{
    var app = require(‘../javascript/app‘);

    app.config([‘$stateProvider‘, ‘$urlRouterProvider‘, function ($stateProvider, $urlRouterProvider)
    {
        var csspathBase = "https://develop-cdn.sinooceangroup.com/libs/seagull2-workflow-responsive/1.0.3";

        //招聘申请-前置页面
        $stateProvider.state(‘recruitRquestFontpage‘, {
            url: ‘/recruitRquestFontpage‘,
            templateUrl: ‘./views/recruitRequest/recruitRquestFontPage.html‘,
            controller: ‘fontPage-controller‘,
            controllerUrl: ‘./javascript/controllers/recruitRequest/fontPage-controller.js‘,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });
        //招聘申请
        $stateProvider.state(‘RecruitRequest‘, {
            url: ‘/RecruitRequest‘,
            useWorkflow: true,
            workflowUrlBase: ‘/RecruitRequestWf‘,
            workflowScene: {
                ‘Draft‘: {
                    templateUrl: ‘./views/recruitRequest/list.html‘,
                    controller: ‘list-controller‘,
                    controllerUrl: ‘./javascript/controllers/recruitRequest/list-controller.js‘
                },
                ‘Approval‘: {
                    templateUrl: ‘./views/recruitRequest/list.html‘,
                    controller: ‘list-controller‘,
                    controllerUrl: ‘./javascript/controllers/recruitRequest/list-controller.js‘
                },
                ‘ReadOnly‘: {
                    templateUrl: ‘./views/recruitRequest/list.html‘,
                    controller: ‘list-controller‘,
                    controllerUrl: ‘./javascript/controllers/recruitRequest/list-controller.js‘
                }
            },
            startupWorkflow: true,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });

        //自定义控件测试
        $stateProvider.state(‘test‘, {
            url: ‘/test‘,
            templateUrl: ‘./views/test/test.html‘,
            controller: ‘test_controller‘,
            controllerUrl: ‘./javascript/controllers/test/test-controller.js‘,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });

        //职位状态更新-前置页面
        $stateProvider.state(‘JobPostStateMaintainList‘, {
            url: ‘/JobPostStateMaintainList‘,
            templateUrl: ‘./views/JobPostStateMaintain/list.html‘,
            controller: ‘list-controller‘,
            controllerUrl: ‘./javascript/controllers/JobPostStateMaintain/list-controller.js‘,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });
        //职位状态更新
        $stateProvider.state(‘JobPostStateMaintain‘, {
            url: ‘/JobPostStateMaintain‘,
            useWorkflow: true,
            workflowUrlBase: ‘/JobPostStateMaintain‘,
            workflowScene: {
                ‘Draft‘: {
                    templateUrl: ‘./views/JobPostStateMaintain/edit.html‘,
                    controller: ‘edit-controller‘,
                    controllerUrl: ‘./javascript/controllers/JobPostStateMaintain/edit-controller.js‘
                },
                ‘ReadOnly‘: {
                    templateUrl: ‘./views/JobPostStateMaintain/edit.html‘,
                    controller: ‘edit-controller‘,
                    controllerUrl: ‘./javascript/controllers/JobPostStateMaintain/edit-controller.js‘
                }
            },
            startupWorkflow: true,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });
        //消息通知
        $stateProvider.state(‘Notify‘, {
            url: ‘/Notify?taskID‘,
            templateUrl: ‘./views/notify/notify-dialog.html‘,
            controller: ‘notify-dialog-controller‘,
            controllerUrl: ‘./javascript/controllers/notify/notify-dialog-controller.js‘,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });
        //录用洽谈-查看
        $stateProvider.state(‘EmployeExecuteView‘, {
            url: ‘/EmployeExecuteView?id&taskID‘,
            templateUrl: ‘./views/EmployeExecute/employed-discuss-view.html‘,
            controller: ‘employed-discuss-view-controller‘,
            controllerUrl: ‘./javascript/controllers/EmployeExecute/employed-discuss-view-controller.js‘,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });
        //录用洽谈
        $stateProvider.state(‘EmployeExecute‘, {
            url: ‘/EmployeExecute‘,
            useWorkflow: true,
            workflowUrlBase: ‘/EmployeExecuteWf‘,
            workflowScene: {
                ‘Draft‘: {
                    templateUrl: ‘./views/EmployeExecute/employed-discuss.html‘,
                    controller: ‘employed-discuss-controller‘,
                    controllerUrl: ‘./javascript/controllers/EmployeExecute/employed-discuss-controller.js‘
                },
                ‘GeneratedNotice‘: {
                    templateUrl: ‘./views/EmployeExecute/employed-discuss.html‘,
                    controller: ‘employed-discuss-controller‘,
                    controllerUrl: ‘./javascript/controllers/EmployeExecute/employed-discuss-controller.js‘
                },
                ‘BackgroundCheck‘: {
                    templateUrl: ‘./views/EmployeExecute/employed-discuss.html‘,
                    controller: ‘employed-discuss-controller‘,
                    controllerUrl: ‘./javascript/controllers/EmployeExecute/employed-discuss-controller.js‘
                },
                ‘ReadOnly‘: {
                    templateUrl: ‘./views/EmployeExecute/employed-discuss.html‘,
                    controller: ‘employed-discuss-controller‘,
                    controllerUrl: ‘./javascript/controllers/EmployeExecute/employed-discuss-controller.js‘
                }
            },
            startupWorkflow: true,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });

        //内部推荐-前置页面
        $stateProvider.state(‘InternalRecommendRequestList‘, {
            url: ‘/InternalRecommendRequestList‘,
            templateUrl: ‘./views/InternalRecommendRequest/list.html‘,
            controller: ‘list-controller‘,
            controllerUrl: ‘./javascript/controllers/InternalRecommendRequest/list-controller.js‘,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });
        //内部推荐更新
        $stateProvider.state(‘InternalRecommendRequest‘, {
            url: ‘/InternalRecommendRequest‘,
            useWorkflow: true,
            workflowUrlBase: ‘/InternalRecommendRequest‘,
            workflowScene: {
                ‘Draft‘: {
                    templateUrl: ‘./views/InternalRecommendRequest/edit.html‘,
                    controller: ‘edit-controller‘,
                    controllerUrl: ‘./javascript/controllers/InternalRecommendRequest/edit-controller.js‘
                },
                ‘ReadOnly‘: {
                    templateUrl: ‘./views/InternalRecommendRequest/edit.html‘,
                    controller: ‘edit-controller‘,
                    controllerUrl: ‘./javascript/controllers/InternalRecommendRequest/readonly-controller.js‘
                }
            },
            startupWorkflow: true,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });

        //面试阶段管理
        $stateProvider.state(‘InterviewManage‘, {
            url: ‘/InterviewManage‘,
            useWorkflow: true,
            workflowUrlBase: ‘/InterviewManageWf‘,
            workflowScene: {
                ‘Draft‘: {
                    templateUrl: ‘./views/InterviewManage/list.html‘,
                    controller: ‘list-controller‘,
                    controllerUrl: ‘./javascript/controllers/InterviewManage/list-controller.js‘
                },
                ‘ReadOnly‘: {
                    templateUrl: ‘./views/InterviewManage/edit.html‘,
                    controller: ‘edit-controller‘,
                    controllerUrl: ‘./javascript/InterviewManage/JobPostStateMaintain/edit-controller.js‘
                }
            },
            startupWorkflow: true,
            requiredLogin: true,
            dependencies: [‘css!‘ + csspathBase + ‘/form‘, ‘ie8css!‘ + csspathBase + ‘/form_ie8‘]
        });
    }]);
});

config.json,common-config.json  配置文件--里面配置了一些常用数据(登录地址,参数等),是在app.js中加入了配置才起的作用,

var commonConfig = require(‘text!../common-config.json‘);
    var config = require(‘text!../config.json‘);
    app.config([‘configureProvider‘, function (configureProvider)
    {
        configureProvider.configure(commonConfig);
        configureProvider.configure(config);
    }]);
    asyncLoader.configure(app);
    module.exports = app;

B-自定义控件示例:

我的自定义控件文件为:angular-seagull2-empprovider.js

//简历评价
(function (window, angular) {
    ‘use strict‘;
    $resumeSrummaryDirective.$inject = [‘$http‘, ‘seagull2Url‘, ‘wfWaiting‘, ‘sogModal‘, ‘sogValidator‘, ‘ValidateHelper‘, ‘IndentityCodeHelper‘, ‘regionType‘];

    function $resumeSrummaryDirective($http, seagull2Url, wfWaiting, sogModal, sogValidator, ValidateHelper, IndentityCodeHelper, regionType) {
        return {
            restrict: ‘E‘,
            replace: true,
            transclude: true,
            scope: { resumeCode: ‘=resumeCode‘ },
            template: ‘<a ng-click="showResumeSrummary()" style="color:blue;margin-left:5px;float:left;cursor:pointer;"><span>面试评价</span></a>‘,
            link: {
                pre: function ($scope, $element, $attrs) {
                    $scope.showResumeSrummary = function () {
                        //简历评价事件
                        $http.post(seagull2Url.getPlatformUrl("/Resume/LoadResumeSrummary?code=" + $scope.resumeCode)).success(function (result) {
                            if (result) {
                                sogModal.openLayer(‘<div><div ng-include="\‘views/common/resume-srummary-template.html\‘"></div></div>‘, [‘$scope‘, function ($modalScope) {
                                    $modalScope.resumeSurmmarys = result;

                                    //关闭按钮事件
                                    $modalScope.close = function () {
                                        $modalScope.closeThisDialog();
                                    };
                                }], undefined, {}, undefined, undefined);
                                wfWaiting.hide();
                            }
                        }).error(function (err, status) {
                            wfWaiting.hide();
                            console.log(err + "||" + status);
                            //sogModal.openMessageDialog(status, result);
                        });
                    };
                }
            }
        };
    }
    //声明模块angular-seagull2-empprovider.resume-srummary
    var module = angular.module("angular-seagull2-empprovider.resume-srummary", [
        ‘angular-seagull2-common‘,
        ‘angular-seagull2-workflow‘]);
    //创建resume-editor模块指令
    module.directive(‘resumeSrummary‘, $resumeSrummaryDirective);

}(window, window.angular));

(function (angular) {
    ‘use strict‘;

    angular.module(‘angular-seagull2-empprovider‘, [
        ‘angular-seagull2-empprovider.recruit-request-view‘,
        ‘angular-seagull2-empprovider.ogu-unit‘,
        ‘angular-seagull2-empprovider.resume-editor‘,
        ‘angular-seagull2-empprovider.resume-srummary‘,
    ]);
}(window.angular));

a-根据结构的分析,要想使该JS起作用,需要在app.js中注入该JS才行(下面只展示了关键代码):

 require(‘angular-seagull2-empprovider‘);

var app = angular.module(‘app‘, [
‘angular-seagull2-empprovider‘,
]);

b-自定义控件JS简单分析:

--->创建控件指令函数--->注入指令函数

C-使用示例:

<resume-srummary resume-code="resumeCode"></resume-srummary>
时间: 2024-11-05 21:59:45

AngularJS_自定义控件_入门学习1的相关文章

Unity3d_学习笔记_入门

转自:http://blog.csdn.net/zlfxy/article/details/8722437 本文内容来自“编程教父”的视频课程. 1.Unity3d一个游戏引擎,可以用来开发很多游戏. 要利用Unity3d开发游戏,我们首先要下载一个Unity3d软件.下载后,下载一个破解补丁,这样就可以正常进行开发了. 2.Unity3d每次只能开启一个工程项目. (1)Unity3d中比较重要的一个对象就是摄像机了,摄像机就相当于我们人的眼睛,有了摄像机,运行程序后,才能够有视野. (2)U

机器学习_深度学习_入门经典(永久免费报名学习)

机器学习_深度学习_入门经典(博主永久免费教学视频系列) https://study.163.com/course/courseMain.htm?courseId=1006390023&share=2&shareId=400000000398149 作者座右铭---- 与其被人工智能代替,不如主动设计机器为我们服务. 长期以来机器学习很多教材描述晦涩难懂,大量专业术语和数学公式让学生望而止步.生活中机器学习就在我们身边,谷歌,百度,Facebook,今日头条都运用大量机器学习算法,实现智能

Android 自定义控件开发入门 (三)

上两次我们从如何自定义控件讲起,列举了View的一些Api,说明了一些在自定义的时候,可以进行重写的方法,然后通过一个例子的两种写法向大家展示了最基本的自定义控件和我们要充分了解并积极重写View方法的精神,这次我们将继续进行学习! 现在请大家回想一下我们使用安卓原生控件时的感受,一个好的控件是可以在xml中进行各种属性的操作的,而自定义控件往往有一些特殊的需求,今天我要讲的就是安卓给自定义控件添加自定义的属性. 下面再给大家具体介绍一下如果自定义的View需要有自定义的属性我们该如何处理: 我

Less入门学习总结

Less入门学习总结 一.什么是Less   css的Less好比是js的Jquery,可以让人们更方遍快捷的使用css,使css代码更简洁,可以减少重复的代码,减少开发人员的工作量. Less CSS是一种动态样式语言,属于CSS预处理语言的一种,它使用类似CSS的语法,为CSS赋予了动态语言的特性,如变量.继承.运算.函数等,更方便CSS的编写和维护. Less中文手册:less.bootcss.com 二.编译工具 1.Koala:国人开发的LESS/SASS编译工具 下载地址:http:

鱼C《零基础入门学习Python》10-17节课时知识点总结

第10讲:列表:一个打了激素的数组 1. 列表都可以存放一些什么东西?  我们说 Python 的列表是一个打了激素的数组,如果把数组比喻成集装箱,那么 Python 的列表就是一个大仓库,Ta 可以存放我们已经学习过的任何数据类型. 2. 向列表增加元素有哪些方法?  三种方法想列表增加元素,分别是:append().extend() 和 insert().    3. append() 方法和 extend() 方法都是向列表的末尾增加元素,请问他们有什么区别?  append() 方法是将

ArcGIS for Desktop入门教程_第四章_入门案例分析 - ArcGIS知乎-新一代ArcGIS问答社区

原文:ArcGIS for Desktop入门教程_第四章_入门案例分析 - ArcGIS知乎-新一代ArcGIS问答社区 1 入门案例分析 在第一章里,我们已经对ArcGIS系列软件的体系结构有了一个全面的了解,接下来在本章中,将通过一个案例来熟悉ArcGIS for Desktop的使用,从解决问题的过程中,逐渐适应ArcGIS桌面的界面和操作方式. 本章的练习数据是一个住宅小区的简单平面示意图,需要在已有的基础上把楼房的轮廓补充完整,并加以整饰,完成一幅地图. 1.1 打开地图文档并浏览

python入门学习

最近闲来无事,搞搞py交易吧! 作为一个快速崛起的语言,python编程确实是好用的不得了,当然这不是说他就可以代替其他语言,这是目前所有语言都不可能做到的: python有他的优点: 简单,简洁,易懂,入门快: 学过python的应该都有体会,python比其他很多语言都要轻便的多,易于编写: 比如python的hello world: #!/usr/bin/python print('hello world') 就这一句就ok了: 简单的了解下python,下面我们来了解下python2和3

Android 自定义控件开发入门(一)

作为一个有创意的开发者,或者软件对UI设计的要求比较高,你经常会遇到安卓自带的控件无法满足你的需求的情况,这种时候,我们只能去自己去实现适合项目的控件.同时,安卓也允许你去继承已经存在的控件或者实现你自己的控件以便优化界面和创造更加丰富的用户体验. 那么怎样来创建一个新的控件呢? 这得看需求是怎样的了. 1.需要在原生控件的基本功能上进行扩展,这个时候你只需要继承并对控件进行扩展.通过重写它的事件,onDraw ,但是始终都保持都父类方法的调用.如从已有的高级控件上继承,例如继承一个TextVi

Android 自定义控件开发入门(二)

上一次我们讲了一堆实现自定义控件的理论基础,列举了View类一些可以重写的方法,我们对这些方法的重写是我们继承View类来派生自定义控件的关键 我通过一个最简单的例子给大家展示了这一个过程,无论是多么复杂的自定义控件,思路总是这样子的,但是因为我们仅仅重写了onDraw方法使得大家觉得怪怪的,作为一个控件,我们居然还要为了他的实现为其增加麻烦的监听,这就不能叫做控件了. 下面再给大家介绍一个经常重写的方法法:publicboolean onTouchEvent (MotionEvent even