2014-01-20 2 views
0

서비스를 사용하여 컨트롤러 사이에 여러 개체 값을 전달 :데이터 보유 내가 서비스를 두 개의 컨트롤러를 가지고 설정

<div ng-controller="FirstCtrl"> 
     <input type="text" ng-model="data.message"> 
     <h1>{{ data.message }}</h1> 
    </div> 

    <div ng-controller="SecondCtrl"> 
     <input type="text" ng-model="data.type"> 
     <h1>{{ data.type }}</h1> 
    </div> 
: 내 HTML에서

var myApp = angular.module('myApp', []); 
myApp.factory('Data', function() { 
    return { message: "This is a message from a service", Type: "This is a type from a service" } 
}); 


function FirstCtrl($scope, Data) { 
    $scope.data = Data; 
} 

function SecondCtrl($scope, Data) { 
    $scope.data = Data; 
} 

을, 나는이 값을 바인딩 입력이

그러나 서비스에서 돌아 오는 메신저는 모두 data.message이고 data.type은 없습니다.

왜 이런가요?

+1

데이터 형식이어야합니다. 입력 - 오타가하나요? – michael

+0

하하하 참으로! 고맙습니다! – Keva161

답변

0

간단한 유형 오류입니다. Factory는 'Type'을 키로 사용하여 Data 객체를 반환합니다. HTML에서는 '유형'대신 키로 '유형'을 사용했습니다.

관련 문제