처음에는 혼란 스럽지만 미안하지만이 문제는 밤 내내 해결됩니다. 수십 가지의 SO 질문과 AngularJS 기사를 읽었으므로 심지어 지금은 내가 어디에 문제인지 아는 경우 :
나는 컨트롤러가 어디 $scope
의 몇 가지 속성에 대한 기본 데이터를 정의하면이 데이터가 나중에 programatically 변경되면 업데이 트를 얻지 못하게 .
...
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/abc/:letter', {templateUrl: template, controller: FilterCtrl}).
otherwise({redirectTo: '/abc/a'});
}])
...
컨트롤러 :
function FilterCtrl($scope, $http, $routeParams) {
$scope.mainfilter = $routeParams.letter;
$scope.listItems = $http.post($scope.url, {'filterType': 'abc', 'letter': $routeParams.letter});
$scope.searchTitle = function(search) {
$scope.mainfilter = 'Film: ';
//just test code to see if the data changes, will be other http call actually
$scope.listItems = $http.post($scope.url, {'filterType': 'abc', 'letter': 'n'});
}
}
홈페이지 마크 업, 뷰가 정의 (Symfony2를, pls는 나뭇 가지 논리를 무시) :
...
<div class="sort cell-1022 transparent-gray-back overflow-fix">
<span class="sort--title">Search by</span>
<select class="sort--selected chzn-select" ng-model="searchtitle" ng-change="searchTitle(searchtitle)">
<option value="">film title</option>
{% for id,title in titles %}
<option value="{{ id }}">{{ title }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="divider transparent"></div>
<article class="wrapper">
<div class="transparent-gray-back" ng-view>
</div>
</article>
여기 내 코드의 간단한 예입니다
템플릿의 중요한 부분은 다음과 같습니다.
<div class="scroll-list nice-scrollbars" >
<span class="heading">{{ mainfilter.toUpperCase() }}</span>
<ul class="item-list">
<li ng-repeat="item in listItems.data | orderBy:order | filter:filter">
<a ng-click="getRelated(item._id)">{{ item.title }}</a>
</li>
</ul>
</div>
주요 문제는 처음 두 줄의 컨트롤러가있는 경우 데이터가 경로 매개 변수에 따라 올바르게 초기화되지만 실행 후 searchTitle()
이 업데이트되지 않습니다. 처음 두 줄을 지울 때 경로에 정의 된 데이터는 당겨지지 않지만 (분명히) searchTitle()
메서드는 mainfilter
필드와 정확히 <li>
을 모두 채 웁니다. 나는 필사적이다, 나는 무언가가 범위에 문제가 있다고 제안하지만, 나는 현재 정보가 너무 많아서 당신의 도움에 감사 할 것이다.
오늘도 비슷한 문제가 있었고,'$ scope. $ apply (function() {...}) '에 함수 ('searchFilter')를 넣는 것이 도움이 되었습니까? –