OK - 그래서 나는 다음과 같은 서비스가 있습니다AngularJS와 -의 값을 기준으로 나머지 API에서 필터 결과 텍스트 상자
angular.module('myApp.services', ['ngResource'])
.factory('STLineup', function($resource){
return $resource('http://someapi.com?filters=location.eventInstance.slug:Slug,artists.tags:ArtistTags,location.name:LocationName',
{Slug: '@Slug', ArtistTags: '@ArtistTags', LocationName: '@LocationName'})
});
그리고 다음 컨트롤러 :
angular.module('myApp.controllers', [])
.controller('MyCtrl1', ['$scope', 'STLineup', function($scope, stl) {
$scope.items = {};
stl.get({'Slug': ':xxxxx-2014', 'ArtistTags': ':electronic|grime', 'LocationName': ':Snakepit'},function(response) {
$scope.items = response.results;
});
$scope.changeCallback = function() {
stl.get({'Slug': ':xxxxxx-2014', 'ArtistTags': ':electronic|grime'},function(response) {
$scope.items = response.results;
});
}
}]);
그리고 다음 지시문을 :
angular.module('myApp.directives', [])
.directive('appLineup', [function() {
return {
restrict: 'AEC',
scope: {
items: '=',
change: '&changeCallback'
},
link: function(scope, elem, attrs){
},
templateUrl: 'templates/lineup.html'
};
}]);
다음 템플릿은 다음과 같습니다.
인터페이스에 추가 5,<input type="text" ng-model="LocationName" ng-change="change()" />
<br/>
<div class="item" ng-repeat="item in items">
<p class="title">{{item.name}}</p>
</div>
다음 사용 :
<app-lineup items="items" change-callback="change()" />
휴!
초기 데이터가로드되고 있지만 change
이벤트가 실행되지 않습니다. 여기서 내가 뭘 잘못하고 있니?!
다음은 app.js의 코드입니다.
angular.module('myApp', [
'ngRoute',
'ngResource',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
$routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
$routeProvider.otherwise({redirectTo: '/view1'});
}]);
당신은 컨트롤러를 사용하는 경우 방법/표시되지 않습니다. – gkalpak
이것은 종자 응용 프로그램에서 곧바로입니다 - app.js의 코드를 추가했습니다 – iwayneo