【发布时间】:2017-03-22 16:29:13
【问题描述】:
大家好,我正在尝试使用 Angular js 将其中一个字段值从一个 html 页面传送到另一个页面。下面是代码sn-ps
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:
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;
});
如果我将元素放在同一个页面中,它可以正常工作,但如果我将它们放在两个不同的 html 页面中,则不会
我哪里做错了,请帮帮我
谢谢你 标记。
【问题讨论】:
-
您的问题需要澄清。当您说“两个不同的 html 页面”时,您是使用角度路由(
http://whatever.com/#/route1、http://whatever.com/#/route2)还是常规路由(http://whatever.com/page1/、http://whatever.com/page2/)? -
常规路由
标签: html angularjs angularjs-scope