こんにちはすべて私は角のjsを使用して、あるhtmlページから別のhtmlページにフィールド値のいずれかを運ぶことを試みています。角度jsを使用してフォームフィールドデータを次のhtmlページに渡すことができません
<body ng-app="myApp">
<div ng-controller="ExampleOneController">
Name:<input type = "text" ng-model="newVar.val">
</div>
<div ng-controller="ExampleTwoController">
<pre>value of name is {{anotherVar.val}}</pre>
</div>
AngularJS:以下のコードは
HTMLスニペットです私は同じページ内の要素を入れたが、私は中に入れない場合場合は正常に動作している
var myApp = angular.module("myApp", []);
myApp.controller("ExampleOneController", function($scope, NewsService) {
$scope.newVar = {
val: ""
};
NewsService.newVar = $scope.newVar;
$scope.news = NewsService.news;
});
myApp.controller("ExampleTwoController", function($scope, NewsService) {
$scope.anotherVar = NewsService.newVar;
$scope.news = NewsService.news;
});
2つの異なるhtmlページ
私は間違っています。助けてください。
ありがとうございます マーク。
あなたの質問は説明が必要です。あなたは "2つの異なるhtmlページ"と言うとき、角度ルーティング( 'http://whatever.com /#/ route1'、' http://whatever.com /#/ route2')、または通常のルーティング:// whatever.com/page1/'、' http:// whatever.com/page2/')? –
通常のルーティング – mark
おそらくこのスレッドと同じです: http://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers – Basilf