angularjs1-3,工具方法,bootstrap,多个module,引入jquery

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>无标题文档</title>
        <script type="text/javascript" src="angular.min.js"></script>
    </head>
    <body>
      <div ng-app="myApp">
          <div ng-controller="firstController">
              {{name}}
              {{isArray}}
              {{name1}}
              {{eq}}
          </div>
      </div>
      <script type="text/javascript">
          var app = angular.module("myApp", []);
          app.controller(‘firstController‘,[‘$scope‘,function($scope){
              /*$scope.name=‘zhangsan‘;
              $scope.arr=[1,2,3];

              $scope.isArray=angular.isArray($scope.arr);
              $scope.name1=angular.uppercase($scope.name);
              $scope.a=‘111‘;
              $scope.b=‘111‘;
              $scope.eq=angular.equals($scope.a,$scope.b);
              console.log($scope.eq);//true

              $scope.a={name:‘张三‘};
              $scope.b={age:10};
              $scope.c=angular.extend($scope.b,$scope.a);
              console.log($scope.c);//Object {age: 10, name: "张三"}

              var json = {"name":"hello","age":"20"};
              console.log(json);//Object {name: "hello", age: "20"}

              $scope.json=angular.toJson(json);
              console.log($scope.json);//{"name":"hello","age":"20"}
              $scope.json=angular.toJson(json,true);
              console.log($scope.json);

              var json = ‘{"name":"hello","age":"20"}‘;
              console.log(json);//{"name":"hello","age":"20"}
              $scope.json=angular.toJson(json);
              $scope.json=angular.fromJson(json);
              console.log($scope.json);//Object {name: "hello", age: "20"}

              $scope.a={name:‘张三‘};
              $scope.b={age:10};
              $scope.c=angular.copy($scope.a,$scope.b);
              console.log($scope.a);
              console.log($scope.b);

              var json = {"name":"hello","age":"20","sex":‘男‘};
              angular.forEach(json,function(val,key){
                  console.log(val);
                  console.log(key);
              });*/

              var json = {"name":"hello","age":"20","sex":‘男‘};
              var results=[];
              angular.forEach(json,function(val,key){
                  console.log(val);
                  console.log(key);
                  this.push(key+‘--‘+val);
              },results);
              console.log(results);

              //绑定对象,作为函数的上下文
              var self={name:‘张三‘};
              var f=angular.bind(self,function(age){
                $scope.info=this.name+‘ is ‘+age;
                console.log($scope.info);
              });
              f(30);

              var f=angular.bind(self,function(age){
                  $scope.info=this.name+‘ is ‘+age;
                  console.log($scope.info);
              },10);
              f();

          }]);
      </script>

    </body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="angular.min.js"></script>
</head>
<body>
<div>
   <!--  <div ng-controller="firstController" ng-app="myApp1">
        {{name}}
    </div>
    <div ng-controller="secondController" ng-app="myApp2">
        {{name}}
    </div>
    var app1 = angular.module("myApp1", []);
    var app2 = angular.module("myApp2",  []);//报错,module只会初始化一次, -->

    <div id=‘div1‘ ng-controller="firstController"
        {{name}}
    </div>
    <div  id=‘div2‘  ng-controller="secondController">
        {{name}}
    </div>
</div>
//bootstrap不是css的bootstrap,一般一个页面只有一个module,bootstrap用于页面初始化多个module,
<script type="text/javascript">
    var app1 = angular.module("myApp1", []);
    var app2 = angular.module("myApp2", []);//报错,module只会初始化一次,
    app1.controller(‘firstController‘,function($scope){
        $scope.name=‘张三‘;
    });
    app2.controller(‘secondController‘,function($scope){
        $scope.name=‘李四‘;

    });
    var div1=document.getElementById(‘div1‘);
    var div2=document.getElementById(‘div2‘);
    document.onclick=function(){//动态加载多个module
        angular.bootstrap(div1,[‘myApp1‘]);
        angular.bootstrap(div2,[‘myApp2‘]);
    }
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="module02.js"></script>
<!-- module02.js:
var app2 = angular.module("myApp2", []);
app2.controller(‘secondController‘,function($scope){
    $scope.name=‘李四‘;
});
app2.controller(‘threeController‘,function($scope){
    $scope.name=‘王五‘;
});-->
</head>
<body ng-app="myApp">
<div>
    <div ng-controller="firstController">
        {{name}}
    </div>
    <div ng-controller="secondController">
        {{name}}
    </div>
    <div ng-controller="threeController">
        {{name}}
    </div>
</div>
<script type="text/javascript">
    var app1 = angular.module("myApp", [‘myApp2‘])//模块的依赖,[‘myApp2‘,‘myApp3‘]可以引入多个,这是插件化引入。
    app1.controller(‘firstController‘,function($scope){
        $scope.name=‘张三‘;
    });
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    //jqueru要放在上面
    <script type="text/javascript" src="jquery-1.11.1.js"></script>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="module02.js"></script>
<!-- module02.js:
var app2 = angular.module("myApp2", []);
app2.controller(‘secondController‘,function($scope){
    $scope.name=‘李四‘;
});
app2.controller(‘threeController‘,function($scope){
    $scope.name=‘王五‘;
});-->
</head>
<body ng-app="myApp">
<div>
    <div ng-controller="firstController">
        <div id="obj1">
        </div>
        {{name}}
    </div>
    <div   ng-controller="secondController">
        {{name}}
    </div>
    <div   ng-controller="threeController">
        {{name}}
    </div>
</div>
<script type="text/javascript">
    var app1 = angular.module("myApp", [‘myApp2‘]);
    app1.controller(‘firstController‘,function($scope){
        $scope.name=‘张三‘;
       // $("#obj1").html(‘<span>尿道嗦嘎电视柜 v邓先生广东省高</span>‘);
           var obj1=document.getElementById(‘obj1‘);
            angular.element(obj1).html(‘这是angularjs中的jqlite‘);
    });
</script>
</body>
</html>
时间: 2024-07-31 14:33:35

angularjs1-3,工具方法,bootstrap,多个module,引入jquery的相关文章

jquery源码解析:jQuery延迟对象Deferred(工具方法)详解1

请先看上一课的回调对象.Deferred是通过extend添加到jQuery中的工具方法.如下所示: jQuery.extend({ Deferred: function( func ) { }, when: function( subordinate /* , ..., subordinateN */ ) { }}); 首先,来介绍下Deferred的使用: var cb = $.Deferred(); setTimeout(function(){ alert(1); cb.resolve()

jQuery操作数组的工具方法

1.前言 很多时候,jQuery的$()函数都返回一个类似数组的jQuery对象,例如$("div")将返回由页面中所有<div-/>元素包装成jQuery对象,这个jQuery对象实际上包含了多个<div-/>元素对应的DOM对象.在这种情况下,jQuery提供了以下几个常用属性和方法来操作类数组的jQuery对象. 1)        length:该属性返回jQuery里包含的DOM元素的个数 2)        context:该属性返回获取jQuery

angularJs中的常用工具方法

前面说过在angularJs中使用 angular.module() 法可创建一个angularJs模块.除此之外,angularJs还提供了一些工具方法供我们使用. angular.isArray() //判断传入的参数是不是数组,是则返回true 否则返回false angular.isDate() //判断传入的参数是不是时间对象,是则返回true,否则返回false angular.isFunction() //判断传入的参数是不是函数,是则返回true,否则返回false angula

angular的工具方法笔记(equals, HashKey)

分别是angular脏值检测的工具方法equals和 类HashKey的使用方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <he

jquery源码解析:jQuery工具方法详解1

jQuery的工具方法,其实就是静态方法,源码里面就是通过extend方法,把这些工具方法添加给jQuery构造函数的. jQuery.extend({       //当只有一个对象时,就把这个对象中的属性和方法扩展到this对象中,这里的this指向jQuery expando: "jQuery" + ( core_version + Math.random() ).replace( /\D/g, "" ), //唯一性,core_version 为jQuery

jquery源码解析:jQuery工具方法详解2

jQuery的工具方法,其实就是静态方法,源码里面就是通过extend方法,把这些工具方法添加给jQuery构造函数的. jQuery.extend({ ...... type: function( obj ) {    //$.type(),判断类型 if ( obj == null ) {   //null,undefined return String( obj );    //返回null,undefined字符串 }     //core_toString = {}.toString 

jQuery晦涩的底层工具方法们

这里整理的是jQuery源码中一些比较晦涩难懂的.内部的.最底层的工具方法,它们多为jQuery的上层api方法服务,目前包括: jQuery.access jQuery.access: function( elems, fn, key, value, chainable, emptyGet, pass ) 在jQuery的众多api方法中,许多方法都有一个非常重要和常见的特征:重载,简单来讲即参数的不同决定了方法的功能不同 例如我们最常使用的几个:jQuery.fn.val().jQuery.

jQuery常用工具方法

前面的话 jQuery提供一些与元素无关的工具方法,不必选中元素,就可以直接使用这些方法.如果理解原生javascript的继承原理,那么就能理解工具方法的实质.它是定义在jQuery构造函数上的方法,即jQuery.method(),所以可以直接使用.而那些操作元素的方法,是定义在构造函数的prototype对象上的方法,即jQuery.prototype.method(),所以必须生成实例(即选中元素)后使用.把工具方法理解成像javascript原生函数那样可以直接使用的方法就行了.下面将

jquery源码之工具方法

jQuery 作为时下前端的"霸主".它的强大已毋庸置疑.简洁,效率,优雅,易用等优点让人很容易对它珍爱有加. 作为js的小菜,为了提升自我等级,根据各大神博客精辟的解析,硬啃了jQuery源码.在此,并不是要解析啥源码啥的(也没到那个级别哈),读书笔记,仅此而已. 所谓磨刀不误砍柴功,jQuery在大展神通之前也做了许多准备工作.比如说他的一些工具方法: 首当其冲的是他的继承扩展方法: jQuery.extend 其实也不是传统意义的继承,说mixin可能更恰当一些. // 首先看看

jquery源码解析:jQuery工具方法详解3

jQuery的工具方法,其实就是静态方法,源码里面就是通过extend方法,把这些工具方法添加给jQuery构造函数的. jQuery.extend({ ...... each: function( obj, callback, args ) {   //$.each(arr , function(i,value){}),第三个参数用于内部调用.此方法就是来遍历数组的,然后取数组中的值进行显示.不能改变原数组arr,跟map一样,但是map返回新数组,而each返回原数组.这里跟原生的forEa