angularJSでかなり新しいし、あるページから別のページに情報を渡そうとしています。AngularJSを使って別のページにデータを渡す方法は?
現在のところ、このコントローラーは表形式で顧客の一覧を表示し、1列は「詳細情報」です。
** adminSearch.html **
<div ng-controller="adminSearch">
...
<tr ng-repeat-start="custObj in customers | filter:custSearch">
<td> {{custObj.id}} </td>
<td> {{custObj.name}} </td>
<td> <a href="#"> More Info </a></td>
</tr>
...
コントローラー:
** adminSearch.js **
app.controller('adminSearch', ['$scope', function($scope) {
$scope.customers = [{id:1, name:'John', email:'[email protected]', phone:'555-1276', account:123456, mylH: '1'},
{id:2, name:'Mary', email:'[email protected]', phone:'800-BIG-MARY', account:123456, mylH: '1'},
{id:3, name:'Mike', email:'[email protected]', phone:'555-4321', account:123456, mylH: '0'}];}]);
私が欲しいものは、ユーザが顧客のいずれかのテーブルから「詳細」をクリックしたときに、それはそれに関するすべての情報を表示する新しいページに行くべきです顧客...
ない新しいコントローラを必要とするもの、新しいページのニーズが、私はそれを推測していてください:
** customerInfo.html **
<div ng-controller="customerInfo"> ... </div>
** customerInfo.js **
app.controller('customerInfo', ['$scope', function($scope) {
}]);
あなたの助けてくれてありがとうございます!
サービスのgetter setterメソッドを使用して、サービスを作成し、ページ全体でデータを共有したい場合があります。 –
ディレクティブを作成します。ディレクティブでは、スコープを定義し、htmlのデータを属性として渡します。 [link] [https://docs.angularjs.org/guide/directive] –
$ rootScopeを使う...これは一番簡単な方法です –