Answer the question
In order to leave comments, you need to log in
Substitute value from one controller to another in Angularjs?
Hello,
tell me there is a code below, how to substitute the value from another controller into the #cqnum input when clicking on the button from (CController)
<div ng-controller="BController" ng-init="init()">
<input type="text" id="cqnum" ng-model="cqnum"/>
<button ng-click="Create2()">Сохранить 2</button>
</div>
<div ng-controller="CController" ng-init="init()" style="height: 100%;width:100%;">
<button ng-click="Create1()">Сохранить 1</button>
</div>
<script>
pqsAppModule.service('shareData', function() {
return {
setData : setData,
getData : getData,
shared_data : {}
}
function setData(data) {
this.shared_data = data
}
function getData() {
return this.shared_data
}
})
</script>
<script type="text/javascript" charset="utf-8">
pqsAppModule.controller('BController',function($scope,shareData) {
$scope.Create2 = function(stat){
console.log('send');
console.log(shareData.getData());
}
});
</script>
<script type="text/javascript" charset="utf-8">
pqsAppModule.controller('CController',function($scope,shareData) {
$scope.cq_id = 0;
$scope.Create1 = function(stat){
$scope.cq_id= 123;
shareData.setData(data=$scope.cq_id);
}
});
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question