controller之间的数据共享(同过factory自定义服务把共享数据传递给各个controller之间)

<div ng-controller="myCtrl">
    <input type="text" ng-model="Date.message">
    <p>
        first:{{Date.message}}
    </p>
</div>
<div ng-controller="last">
    last:{{Date.message}}
</div>




var app = angular.module("app",[])
app.factory("Date",function () {
    return {
        message :"数据共享"
    }
})
app.controller('myCtrl',function ($scope,Date) {
        $scope.Date =Date
});

app.controller('last',function ($scope,Date) {
    $scope.Date =Date
})

 

posted @ 2017-06-01 16:24  牛奶很忙  阅读(274)  评论(0编辑  收藏  举报