清除子项范围(包括模板更改)

时间:2017-02-13 11:31:25

标签: javascript jquery angularjs templates angularjs-ng-include

我有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

0 个答案:

没有答案