Answer the question
In order to leave comments, you need to log in
How to properly pass $scope from child controller?
view:
<div ng-controller="ParentCtrl">
<div ng-controller="ChildCtrl">
<input type="text" ng-model="myText">
</div>
<button ng-click="click()">Click</button>
</div>
angular.module('app', [])
.controller('ParentCtrl', [$scope, ParentCtrl])
.controller('ChildCtrl', [$scope, ChildCtrl]);
function ParentCtrl($scope) {
$scope.name = {title: ''};
$scope.click = function() {
console.log($scope.name);
}
}
function ChildCtrl($scope) {
$scope.$parent.name.title = $scope.myText;
}
Answer the question
In order to leave comments, you need to log in
How to solve this problem correctly?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question