AngularJS - 刷新元素导致重新加载视图

时间:2014-11-04 10:16:42

标签: angularjs

我要刷新AngularJS中的元素,但以下代码隐藏了整个ng-view内容

var firstModule = angular.module('myModule', ['ngRoute', 'ngAnimate']);

    var mainDataServiceInjectParams = ['$http', '$q'];

    var mainFactory = function ($http, $q) {
        var mainDataService = {};
        mainDataService.refreshStatus = function (id) {
            return $http.get('/api/values/' + id).then(function (results) {
                return results.data;
            });
        };

        return mainDataService;
    };

    mainFactory.$inject = mainDataServiceInjectParams;
    firstModule.factory('mainService', mainFactory);

    firstModule.controller('myCtrl', function ($scope, $http, mainService) {
        $scope.TST = {};

        $scope.clickMe = function (id) {
            $scope.loading = true;

            mainService.refreshStatus(id).then(function (results) {
                $scope.TST = 'abc';
                $scope.loading = false;
            });
        }
    });

   firstModule.config(function ($routeProvider) {
       $routeProvider.when("/status/:id", {
             templateUrl: 't.html',
             controller: 'myCtrl'
         });
   });

t.html

<a class="btn btn-primary btn-mini" href="#" ng-click="clickMe(321)">Refresh</a>
{{TST}}
点击t.html链接后,

整个Refresh内容消失了。为什么?

修改

我只需从href="#"

中移除<a>内的t.html

0 个答案:

没有答案