AngularJS watch an object property in an object array

后端 未结 4 1617
日久生厌
日久生厌 2021-02-06 20:56

I have this data in my controller

    $scope.data = {
        home: {
            baseValue: \"1\",
            name: \"home\"
        },
        co         


        
4条回答
  •  萌比男神i
    2021-02-06 21:17

    Based on your question, you can use ngChange to watch changes of baseValue and trigger the function.

    HTML

    Name: {{item.name}}
    BaseValue:

    Controller

    $scope.baseValueChange = function(baseValue) {
        console.log("base value change", baseValue);
    }
    

    If you a more sophisticated version which can get oldValue and newValue, you can refer to this plunkr - http://plnkr.co/edit/hqWRG13gzT9H5hxmOIkO?p=preview

    HTML

    Name: {{item.name}}
    BaseValue:

    Controller

    $scope.baseValueChange = function(oldVal, newVal) {
        console.log("base value change", oldVal, newVal);
    }
    

提交回复
热议问题