Windows Phone Panorama with AngularJS

爱⌒轻易说出口 提交于 2019-12-03 12:51:53
Michael Dausmann

This appears to be a question about sharing state between different instances of a controller (the 'real' 1 panel and the 'fake' "1" panel) and it has been asked before....

I have two divs with the same ng-controller in AngularJS, how can I make them share information?

I like the answer suggesting a service to share state between instances...

var app = angular.module('myapp', []);

app.service('myservice', function(){
    this.data = "Hi, I'm shared"
});

app.controller('mycontroller', ['$scope', 'myservice', function ($scope, myservice) {
    $scope.setData = function(newData){myservice.data = newData};
    $scope.getData = function(){return myservice.data};
}]);

Here is a working fiddle that demonstrates the approach

http://jsfiddle.net/michaeldausmann/WMPv3/#base

Michael

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!