2017-09-14 6 views
-1

ngモデルがアドレスを返すような角度のhtmlページがあり、他のhtmlページに同じアドレスを表示したいと思います。どうやってするの?そして、私のコードはモデルの値を別のページに表示する方法

<input type="text" class="form-control" ng-model="Item" placeholder="Enter the IP Address"/> 
+0

をあなたは、ページ間を移動するには、UI-ルータまたは別のルータを使用していますか?その場合は、モデルを「次のページ」の解決に渡す必要があります。 – rrd

+0

フランクになるにはng route @rrdの使い方は分かりません – venu

答えて

0

であるあなたは、このように同様に行うことができます。

var app = angular.module('myApp', []); 
 
    app.controller('myCtrl', function($scope,$rootScope) { 
 

 
    \t $rootScope.$on('eventName', function(event, args) { 
 
    \t \t $scope.emitMessage = args; 
 
     }); 
 
    }) 
 
    .controller('myCtrl2', function($scope,$rootScope) { 
 
     $scope.onclick = function() { 
 
     \t $rootScope.$emit('eventName',{msg: 'my message'}); 
 
     }; 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
    <div ng-app="myApp"> 
 
    <div ng-controller="myCtrl"> 
 
     <p>Message Emitted: {{emitMessage.msg}}</p> 
 
    </div> 
 

 
    <div ng-controller="myCtrl2" 
 
     <button ng-click="onclick()"> click me to emit message</button> 
 
    </div> 
 
    </div>

関連する問題