angular.extend(dst,src)的简单示例

自我认为这个方法跟angular.copy(src,dst)有点相似。在angular.extend({},src)时,就可以画等号。这个src只代表一个对象。代码如下:(注意这个src可以有多个对象)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>angular.extend(dst,src)</title>
</head>
<body>
    <script src="../materialDesignfile/angular.min.js"></script>
    <div ng-app="myApp" ng-controller="myCtrl" ng-cloak>
        <button ng-click="extendUser()">user2</button>
        <pre>{{user2|json}}</pre>
    </div>
    <script>
        (function () {
            "use strict";
            angular.module("myApp",[]).controller("myCtrl",['$scope',function ($scope) {
                var user={name:"ouyangfeng",age:19};
                var user3={name2:"sixi",age3:6,height:180}
                $scope.extendUser=function () {
                   $scope.user2= angular.extend({},user,user3);
                }
            }])
        })();
    </script>
</body>
</html>

 

posted @ 2017-10-04 00:55  技术让世界更精彩  阅读(647)  评论(0编辑  收藏  举报