2017-09-14 28 views
-1

我有一個帶有角度的HTML頁面,其中ng模型返回一個地址,我想在其他html頁面中顯示相同的地址。怎麼做?而我的代碼是如何將模型值顯示到另一個頁面

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

您正在使用的用戶界面的路由器或其他路由器在頁面之間移動?如果是這樣,您需要將模型傳遞到「下一頁」頁面的解決方案中。 – 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>

相關問題