AngularJS access parent scope from child controller

前端 未结 9 1741
南方客
南方客 2020-11-22 07:30

I\'ve set up my controllers using data-ng-controller=\"xyzController as vm\"

I have a scenario with parent / child nested controllers. I have no problem

9条回答
  •  悲&欢浪女
    2020-11-22 07:52

    Some times you may need to update parent properties directly within child scope. e.g. need to save a date and time of parent control after changes by a child controller. e.g Code in JSFiddle

    HTML

    event.date = {{event.date}}
    event.time = {{event.time}}
    event.date = {{event.date}}
    event.time = {{event.time}}

    event.date:
    event.time:

    JS

        function Parent($scope) {
           $scope.event = {
            date: '2014/01/1',
            time: '10:01 AM'
           }
        }
    
        function Child($scope) {
    
        }
    

提交回复
热议问题