角度が新しいです。私は、あなたがデータ転送のための角度のサービスを使用することによって、この目的を達成することができ、事前のおかげ別のコントローラのコントローラスコープにアクセスします。
<body ng-app="myApp">
<div ng-controller="myCtrl">
First Name: <input type="text" ng-model="fName"><br><br>
Last Name : <input type="text" ng-model="lName">
<p ng-bind="fullName()"></p>
</div>
<div ng-controller="mySecondCtrl">
Father Name: <input type="text" ng-model="fathName"><br><br>
Mother Name:<input type="text" ng-model="mothName">
<p>
<strong>Paren name:</strong>
<span>Mr.{{fathName}},</span>
<span>Ms.{{mothName}}</span>
</p>
</div>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller("myCtrl",myFunction);
function myFunction($scope){
$scope.fName = "";
$scope.lName = "";
$scope.fullName = function(){
return $scope.fName +" "+ $scope.lName
}
}
app.controller("mySecondCtrl",mySecondFunction);
function mySecondFunction($scope){
//I want to access the fullName() function here
}
</script>
</body>
関係2のコントローラで '$ braodcast'と' $ on'関数を使うか、コントローラ間で 'factory'を使ってデータを共有してください –
thanks [Matthew Walton](http://stackoverflow.com/users/241544/matthew-walton ) –
あなたはAngularJS 2を学んでいるはずですが、GoogleがAngularJS 2でより良い方法を見つけたことを明確に述べています。 –