cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div ng-app="scope">
  <h3>$scope.$watch</h3>
  <div ng-controller="ScopeWatchCtrl"><button ng-click="change()">改变值</button>
    <span>watch value now :{{data}}</span>
    <span>watch value old:{{watchData}}</span>
  </div>
 <h3>$scope.$watch with Controller as </h3>
  
  <div ng-controller="ControllerAsCtrl as vm"><button ng-click="vm.change()">改变值</button>
    <span>watch value now :{{vm.data}}</span>
    <span>watch value old:{{vm.watchData}}</span>
  </div>
</div>
            
          
!
            
              angular.module('scope', [])
  .controller('ScopeWatchCtrl', function($scope) {
    $scope.data = 0;
    $scope.watchData = ''
    $scope.change = function() {
      $scope.data = $scope.data + 1;
    }
    $scope.$watch('data', function(newVal, oldVal) {
      $scope.watchData = oldVal;
    })
  })

.controller('ControllerAsCtrl', function($scope) {
  vm = this;
  vm.data = 0;
  vm.watchData = ''
  vm.change = function() {
      vm.data = vm.data + 1;
    }
    // 如果界面上controller as some ,这里要写成some.data
  // $scope.$watch('vm.data', function(newVal, oldVal) {
  //     vm.watchData = oldVal;
  //   })
    // 需要和view的as后的别名一样,如果想直接监听vm.data使用如下函数的方式
  $scope.$watch(function() {
    return (vm.data);
  }, function(newVal, oldVal) {
    vm.watchData = oldVal;
  })
})
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console