New to Angular - Computed Variables

前端 未结 7 1514
一个人的身影
一个人的身影 2021-02-04 00:33

I am moving to Angular from Knockout, and I have a few issues. I\'m assuming that I must be doing something a non-angular type of way.

http://jsfiddle.net/LostInDaJungle

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 01:23

    The $watch function that is made available through the $scope variable is best for this job in my opinion.

    $scope.$watch(function(scope) { return scope.data.myVar },
                  function(newValue, oldValue) {
                      document.getElementById("myElement").innerHTML =
                          "" + newValue + "";
                  }
                 );
    

    The $watch function takes in a: value function & a listener function

    The above example is taken from this awesome article: http://tutorials.jenkov.com/angularjs/watch-digest-apply.html

    After reading through it, I learnt a lot and was able to implement the solution I was looking for.

提交回复
热议问题