[AngularJS] angular.copy()
Angular angularjs copy
2023-09-14 09:00:56 时间
<!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8"> <title>Egghead Videos</title> <link rel="stylesheet" href="./topcoat-desktop-light.min.css"> <link rel="stylesheet" href="./bootstrap-theme.min.css"> <link rel="stylesheet" href="./bootstrap.min.css"> <script type="text/javascript" src="./angular.min.js"></script> <script type="text/javascript" src="./angular-animate.min.js"></script> <script type="text/javascript" src="./app.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/1.13.2/TweenMax.min.js"></script> </head> <body ng-app="app" ng-controller="AppCtrl"> <form> <input type="text" ng-model="copyContact.firstName" /> <button ng-click="saveContact()">Save</button> </form> <div class="div" style="margin-top: 40px;"></div> <table class="table table-striped"> <thead> <tr> <td>First</td> <td>Last</td> <td>Phone</td> </tr> </thead> <tbody> <tr ng-repeat="contact in contacts" ng-click="selectContact(contact)"> <td>{{contact.firstName}}</td> <td>{{contact.lastName}}</td> <td>{{contact.phone}}</td> </tr> </tbody> </table> </body> </html>
var app = angular.module("app", []); app.factory('Contacts',function($http){ return{ fetchContacts: function(callback){$http.get('./contacts.json').success(callback)} } }) app.controller('AppCtrl', function($scope, Contacts){ $scope.selectedContact = null; $scope.copyContact = null; Contacts.fetchContacts(function(Contacts){ $scope.contacts = Contacts; }); $scope.selectContact = function(contact){ $scope.selectedContact = contact; $scope.copyContact = angular.copy($scope.selectedContact); } $scope.saveContact = function(){ $scope.selectedContact.firstName = $scope.copyContact.firstName; } });
相关文章
- [ngx-formly] Dynamically disable a Form field with Angular Formly
- [Angular] Use Angular components in AngularJS applications with Angular Elements
- [Angular] Custom directive Form validator
- [Angular] Ngrx/effects, Action trigger another action
- [AngularJS] Isolate State Mutations in Angular Components
- [Immutable + AngularJS] Use Immutable .List() for Angular array
- [Angular 2] 7. Event
- [Angular 2] 6. Binding (not .apply(), .digest())
- [Angular 2] 5. Hello World (es5)
- [AngularJS] angular-schema-form -- 1
- [AngularJS] Lazy loading Angular modules with ocLazyLoad
- [AngularJS] Using Services in Angular Directives
- [AngularJS] Angular 1.3 new $q constructor
- [AngularJS] Angular 1.3 Anuglar hint
- [AngularJS]25. Built-in Angular Services
- [Angular Directive] Build a Directive that Tracks User Events in a Service in Angular 2
- [AngularJS] Angular 1.5 $transclude with named slot
- [AngularJS] Sane, scalable Angular apps are tricky, but not impossible.
- [AngularJS] Angular 1.3 ngAria - 2
- [AngularJS] Angular 1.3 new $q constructor
- [AngularJS] Angular 1.3 Anuglar hint
- [AngularJS] Using angular.bootstrap to Initialize Your App
- [Angularjs]angular ng-repeat与js特效加载先后导致的问题
- 关于 Angular 工程文件 angular.json 里的 inlineCritical 属性