i have tow controllers in Angularjs and want to use scope between this controllers. in first controller i get data from server and put in scope.myData. this scope have many item that i write one item. in second controller i have query scope that init by myData.title scope from first controller. but myData.title scope is undefind for second controller while it have correct value. in fact not send myData.title value to init function while i write it such this {{myData.title}} in second controller display it value. what is my problem?
my code like this :
app.controller("Controller1",function ($scope, $http) {
$scope.myData = {
title:""
}
$scope.getData = function(){
if(marketerId != null){
$http.get('/getData')
.success(function(data, status, headers, config) {
$scope.myData = data;
})
.error(function(error, status, headers, config) {
console.log(status);
});
}
};
}
and my second controller is
app.controller("Controller2",function ($scope, $http) {
$scope.query = "";
this.init = function (query) {
$scope.query = query;
}
}
and in html page my code is :
<div ng-controller='controller1 as c1'>
<div ng-controller='controller2'>
<input type='text' ng-model='query' ng-init='c1.init(myData.title)' >
</div>
</div>