zoukankan      html  css  js  c++  java
  • angular 琐碎

    1、controller 只要在一个地方引用就可以了,路由的时候不用指定controller了,在HTML中指定就可以了,否则会初始化两次
    2、angular 模块间的服务无层级关系,相互可见。本质是angularjs将所有模块中的所有服务混入了应用级别的单一命名空间里,顒,对应的每个名字只存在唯一的服务。我们利用这点可以在依赖某模块的同事去覆盖此模块提供的服务。
        父模块中的服务会覆盖子模块中同名的服务。
    3、可以将自定义的东西新建一个模块,依赖ng 然后 在需要使用的地方依赖此模块就可以了
    4、controller之间通信是通过事件冒泡$emit 及广播$boradcast 来传递
    5、更改默认 取值
        myMod.config(function($interpolateProvider){
            $interpolateProvider.startSymbol(‘[[’);
            $interpolateProvider.endSymbol(‘]]’);
    })
    6、创建自定义provider后在使用时要加上Provider后缀
    7、form 
        任意元素上(form元素好像不好使)通过ng-form="formname" 指定一个form
        在此元素内的input元素通过指定name属性就可以在绑定到form作用域上
        
        表单验证,最常使用 ng-minlength,mg-maxlength,ng-pattern="/^d?$/"
        表单及单个验证元素上都有 $valid,$invalid,$pristine,$dirty
      select标签 pattern无效,只要选择了option就是验证通过的
            ng-show="userForm.lastName.$invalid"
    8 、ui-router
    9、angular 执行 表达式
        $scope.$eval 在某个作用域下执行,可以用来解析属性为对象 scope.$eval(attrs.myDateTime); //"{link:'#dpt'}"
        $parse 解析表达式
    10、获取自定义指令的内容
        attrs.指令名称
    11、ui-router 跳转带参数的url
    .state('/search', { //搜索
    url: '/search?query',
    。。。
    $state.go('/search',{query:$scope.searchfield});
    12、变量过大,影响性能,比如图片数据
    13、chrome中border-top-style solid,否则感觉有黑色边框
    14、异步、动态 注册服务 $provide 配置阶段注入,通过$injector 在运行阶段取出或者直接注入
    15、自定义指令模板里包含自定义指令? 动态编译指令 http://blog.csdn.net/yy374864125/article/details/39289019
        element.append($compile(html.join(' '))(scope));
    16、通过使用this 进行二次表达式计算
    17、angular.injector,$injector.invoke 执行注入,$controller 获取controller对象进行执行
    1. angular.bootstrap(document, ['app']);
    2. if (window.__karma__) { //单元测试
    3. angular.module('app').provider({
    4. $rootElement: function () { //在获取$location 之前必须要有$rootElement
    5. this.$get = function () {
    6. return angular.element('<div ng-app></div>');
    7. };
    8. }
    9. });
    10. window.my$injector = angular.injector(['app']); //必须在bootstrap之后才能获取injector
    11. }

    1. my$injector.invoke(function (_$controller_, _$rootScope_, _$myhttp_, _$location_) {
    2. $controller = _$controller_;
    3. $rootScope = _$rootScope_;
    4. $myhttp = _$myhttp_;
    5. $location = _$location_;
    6. });
    1. var $scope = $rootScope.$new();
    2. $controller('logqryController', {$scope: $scope, $myhttp: $myhttp, $location: $location});
    3. expect($scope.tabPage).toBe('/public/views/logqry_sub.html');

    18、将angular 中scope与dom元素一一对应起来
    1. scope = angular.element($0).scope();
    2. scope.$id; // "003"
    3. function getScope(id) {
    4. var elem;
    5. $('.ng-scope').each(function () {
    6. var s = angular.element(this).scope(),
    7. sid = s.$id;
    8. if (sid == id) {
    9. elem = this;
    10. return false; // stop looking at the rest
    11. }
    12. });
    13. return elem;
    14. }
    来自为知笔记
    http://www.zhihu.com/question/36040694/answer/65892270?utm_campaign=webshare&utm_source=weibo&utm_medium=zhihu
     




  • 相关阅读:
    c#中using System.Runtime.Serialization.Json;不能引用
    VS2013 当前不会命中断点还未为文档加载任何符号
    windows2008 设置会话超时时间
    服务没有及时响应启动或控制请求 1053
    IIS装好了无法访问localhost
    Shiro笔记——简介、 架构分析
    Java 连接使用 Redis
    Java 连接操作 Redis 出现错误
    网络方面的常用命令 & 常用端口介绍
    Redis 配置文件及命令详解
  • 原文地址:https://www.cnblogs.com/vvch/p/4958932.html
Copyright © 2011-2022 走看看