sharing data between controllers

6738 단어 controller
sharing data between controllers 
factory(0 서비스로 데이터 공유 가능
<!DOCTYPE html >

<html ng-app="demo">
<head>
    <title></title>
    <script src="angular.min.js" type="text/javascript"></script>
</head>
<body>
<div ng-controller="firstCtl">
        <input type="text" ng-model="data.message" />
        <h1>{{data.message}}</h1>
    </div>
    <div ng-controller="secondCtl">
        <input type="text" ng-model="data.message" />
        <h1>{{data.message}}</h1>
    </div>
</body>
<script>
    var demo = angular.module("demo", []);
    demo.factory("dataServices", function () {
        return {message:"Jackey"};
    });
    demo.controller("firstCtl", function ($scope, dataServices) {
        $scope.data = dataServices;
    });
    demo.controller("secondCtl", function ($scope, dataServices) {
        $scope.data = dataServices;
    });
</script>
</html>

좋은 웹페이지 즐겨찾기