我有HTML代码:
<select ng-model="category" ng-change="categoryChanged(category)" class="form-control"
data-ng-options="category as category.name for category in categories">
<option value="">All Categories</option>
</select>
<div ng-include="subCategoryTemplate"></div>
我的控制器代码是:
$scope.categoryChanged= function (category) {
if (category) {
templateService.getSubCategoryTemplate({ categoryId: category.id }).$promise.then(
function (model) {
if (model) {
$scope.subCategoryTemplate = model.subCategoryTemplate;//Here I am getting on Template Path from the server
$scope.carCompanies = model.carCompanies;
}
},
function (error) {
});
}
$scope.filer = function () {
alert($scope.selectedCarCompany.id);
}
};
模板HTML是:
<select ng-model="$parent.selectedCarCompany" class="form-control"
data-ng-options="carCompany as carCompany.name for carCompany in carCompanies">
<option value="">All Car Companies</option>
</select>
我的情景是:
第一次,当categoryChanged
被调用时,ng-include
会加载模板,用户会选择设置carCompany
$scope
的属性selectedCarCompany
。但即使用户从下拉列表更改类别并且categoryChanged
事件将模板更改为其他视图,仍然$ scope的selectedCarCompany
具有先前所选模板的值。有没有办法清除ng-include模板更改的$scope
?