我在角度应用程序中使用如下:
app.service('sharedProperties', function () {
var property;
return {
getProperty: function () {
return property;
},
setProperty: function(value) {
property = value;
}
};
});
$scope.Somefunc= function(Mname)
{
$http.post("SomeServlet",{
"name": Mname,
}).then(function(response) {
sharedProperties.setProperty(response.data);
window.location = "/blabla/page2.html";
});
};
在第2页(另一个控制者)中,我得到了值:
app.controller('controller2', function($scope,$http,sharedProperties) {
$scope.UserProperties = sharedProperties.getProperty();
});
并且它不起作用,总是我未定义。
答案 0 :(得分:0)
为了使其正常工作,您必须设置角度路由功能,该功能将在不刷新当前页面的情况下移动到另一页面(也称为SPA - 单页应用程序)。
看看here,在页面末尾的示例中,迷你系统中有不同的页面和文件。
我提醒你,angular应用于单页面应用程序,所以如果刷新页面并将其更改为另一个页面 - 你就会失去使用它的重点。