0
我有兩個控制器和設置一個服務以保存數據控制器之間傳遞多個對象的值:使用服務
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;
}
在我的HTML,我有輸入結合這些值:
<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>
但是,所有即時從服務退回的是我的data.message
,並沒有任何內容data.type
。
這是爲什麼?
它應該是data.Type - 只有一個錯字? – michael
確實哈哈哈!謝謝! – Keva161