欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

AngularJS API之copy深拷貝詳解及實例

 更新時間:2016年09月14日 14:56:31   作者:xingoo  
這篇文章主要介紹了AngularJS API之copy深拷貝詳解及實例的相關(guān)資料,需要的朋友可以參考下

angular提供了一個可以復(fù)制對象的api——copy(source,destination),它會對source對象執(zhí)行深拷貝。

使用時需要注意下面幾點:

  1. 如果只有一個參數(shù)(沒有指定拷貝的對象),則返回一個拷貝對象
  2. 如果指定了destination,則會深拷貝對象復(fù)制給destination
  3. 如果source是null或者undefined,那么會直接返回source
  4. 如果source就是desitination,那么會報錯。

下面看看使用樣例:

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script>
</head>
<body ng-app="copyExample">
  <div ng-controller="ExampleController">
    <form novalidate class="simple-form">
      Name: <input type="text" ng-model="user.name" /><br />
      E-mail: <input type="email" ng-model="user.email" /><br />
      Gender: 
      <input type="radio" ng-model="user.gender" value="male" />
      male
      <input type="radio" ng-model="user.gender" value="female" />
      female
      <br />
      <button ng-click="reset()">RESET</button>
      <button ng-click="update(user)">SAVE</button>
    </form>
    <pre>form = {{user | json}}</pre>
    <pre>master = {{master | json}}</pre>
  </div>

  <script>
  angular.module('copyExample', [])
  .controller('ExampleController', ['$scope', function($scope) {
    $scope.master= {};
    
    var test1;
    console.log(angular.copy(test1));//undefined
    var test3=null;
    console.log(angular.copy(test2));//undefined

    var test2 = "a";
    // console.log(angular.copy(test2,test2));//error!!

    $scope.update = function(user) {
      // Example with 1 argument
      $scope.master= angular.copy(user);
    };

    $scope.reset = function() {
      // Example with 2 arguments
      angular.copy($scope.master, $scope.user);
      console.log($scope.master);
      console.log($scope.user);
    };

    $scope.reset();
  }]);
  </script>
</body>
</html>




以上就是對AngularJS API之copy深拷貝的資料整理,后續(xù)繼續(xù)補充相關(guān)資料,謝謝大家對本站的支持!

相關(guān)文章

  • 使用Angular內(nèi)置模塊進行HTTP請求

    使用Angular內(nèi)置模塊進行HTTP請求

    這篇文章主要介紹了使用Angular內(nèi)置模塊進行HTTP請求方法步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-10-10
  • Angular2數(shù)據(jù)綁定詳解

    Angular2數(shù)據(jù)綁定詳解

    本篇文章主要介紹了Angular2數(shù)據(jù)綁定的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-04-04
  • AngularJS中下拉框的高級用法示例

    AngularJS中下拉框的高級用法示例

    這篇文章主要介紹了AngularJS中下拉框的高級用法,結(jié)合實例形式分析了AngularJS下拉框的遍歷、選擇、綁定、顯示等功能實現(xiàn)方法,需要的朋友可以參考下
    2017-10-10
  • Angular2 (RC4) 路由與導(dǎo)航詳解

    Angular2 (RC4) 路由與導(dǎo)航詳解

    這篇文章主要介紹了Angular2 (RC4) 路由與導(dǎo)航的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • 淺析Angular19 自定義表單控件

    淺析Angular19 自定義表單控件

    這篇文章主要介紹了Angular19 自定義表單控件的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2018-01-01
  • angular2中Http請求原理與用法詳解

    angular2中Http請求原理與用法詳解

    這篇文章主要介紹了angular2中Http請求原理與用法,結(jié)合實例形式分析了AngularJS中http相關(guān)模塊實現(xiàn)http服務(wù)請求與相應(yīng)的相關(guān)操作技巧,需要的朋友可以參考下
    2018-01-01
  • Angular中使用MathJax遇到的一些問題

    Angular中使用MathJax遇到的一些問題

    這篇文章主要給大家介紹了關(guān)于Angular中使用MathJax遇到的一些問題,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友下面來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • AngularJS入門教程之雙向綁定詳解

    AngularJS入門教程之雙向綁定詳解

    本文主要介紹AngularJS 雙向綁定,這里整理了詳細的知識資料并講解,而且附有代碼示例,有興趣的小伙伴可以參考下
    2016-08-08
  • Angular彈出模態(tài)框的兩種方式

    Angular彈出模態(tài)框的兩種方式

    這篇文章主要介紹了Angular彈出模態(tài)框的兩種方式,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-10-10
  • 淺析AngularJS Filter用法

    淺析AngularJS Filter用法

    系統(tǒng)的學(xué)習(xí)了一下angularjs,發(fā)現(xiàn)angularjs的有些思想根php的模塊smarty很像,例如數(shù)據(jù)綁定,filter。如果對smarty比較熟悉的話,學(xué)習(xí)angularjs會比較容易一點,這篇文章給大家介紹angularjs filter用法詳解,感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12

最新評論