<body ng-app='fruitApp'>
<div ng-controller='nameController'>
<p>variable : {{variable}}</p>
<p>Title : {{title}}</p>
<p>Items.variable : {{Items.variable}}</p>
</div>
</body>
var app = angular.module('fruitApp',[]);
app.factory('Items',function(){
var title='Hello, ';
function getTitle(name){
return title+name;
}
return {
variable : "this is public",
getTitle : getTitle
}
});
function __nameController($scope,Items){
//service 객체를 바로 사용해도 되고,
$scope.title = Items.getTitle('Jteve');
$scope.variable = Items.variable;
//service 객체를 모델에 연결하고, VIEW에서 호출해도 된다.
$scope.Items = Items;
}
app.controller('nameController',__nameController);
.selected{
background-color: lightgreen;
}