如何将模型值显示到另一页面

时间:2017-09-14 13:49:54

标签: javascript html angularjs

我有一个带有角度的html页面,其中ng模型返回一个地址,我想在其他html页面中显示相同的地址。怎么做?我的代码是

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

1 个答案:

答案 0 :(得分:0)

你可以这样做:

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

    	$rootScope.$on('eventName', function(event, args) {
    		$scope.emitMessage = args;
        });
    })
    .controller('myCtrl2', function($scope,$rootScope) {
        $scope.onclick = function() {
        	$rootScope.$emit('eventName',{msg: 'my message'});
        };
    });
&#13;
    <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>
&#13;
&#13;
&#13;