1
こんにちは、私のすべての要件は、工場で別のコントローラでget setメソッドを使用して入力フィールドのデータを共有することです。不明なプロバイダ:myFactProvider < - myFact < - thirdCtrl
angular.module('dataModule',[]).factory('myFact',function($http){
var user = {};
return {
getDetails: function() {
return user ;
},
setDetails : function (name,add,number) {
user.name = name;
user.add = add;
user.number = number;
}
}
});
ここにコントローラコードがあります。ここで
angular.module('dataModule',[]).controller('thirdCtrl',function(myFact,$scope) {
$scope.saw=function(){
alert("hello get set method");
$scope.user=myFact.user.getDetails();
console.log(user);
};
});
ここに私のhtmlコード
<div ng-controller="thirdCtrl">
<h1>hello gaurav come here after click one.</h1>
<div>
<lable>NAME</lable>
<div><input type="text"ng-model="user.name"></div>
</div>
<div>
<lable>ADDRESS</lable>
<div><input type="text"ng-model="user.add"></div>
</div>
<div>
<lable>MOBILE</lable>
<div><input type="number"ng-model="user.number"></div>
</div>
</br>
</br>
<button type="button" ng-click="saw()">Click</button>
</div>
は「私のapp.js
var app = angular.module('sapient',['ui.router','dataModule']);
app.config(['$stateProvider','$urlRouterProvider',function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('one', {
url: '/one',
templateUrl: 'view/sap.html',
controller: 'sapCtrl'
})
.state('two', {
url: '/two',
templateUrl: 'view/two.html',
controller: 'secondCtrl'
})
.state('three', {
url: '/three',
templateUrl: 'view/three.html',
controller: 'thirdCtrl'
});
$urlRouterProvider.otherwise('two');
}])
任意の提案、事前
最初。ありがとう、あなたは私の時間を節約します。 –
問題はありません、それはあなたが最初に作成するものに依存します。モジュールを作成する必要があるのは、最初に使用される場所です。その後、毎回検索するだけです。 –