【问题标题】:angularjs switch between directive templateurl and $http serviceangularjs 在指令 templateurl 和 $http 服务之间切换
【发布时间】:2014-05-13 02:30:45
【问题描述】:

我有以下指令

app.directive('myPage', function() {
    return {
        restrict: 'E',
        templateUrl: app.urlBuilder('about')
    }
})

默认会加载该指令

为了切换标签,我已经加载了多个页面作为标签内容,为此我使用了 $http 服务。

这是我的html

<my-page></my-page>
<div>{{datas}}</div>

我的控制器

app.controller('PageController', ['$scope', '$http', 'PageService', function($scope, $http, PageService) {
    $scope.changePanel = function(url) {

        PageService.getPageTemplate(url).success(function(data) {
            $scope.datas = data;
        })

    }
}])

问题最初是用 about.html 加载的,而 changePanel 是单击事件,而单击事件发生时,将加载并创建新页面 $scope 并在模板中用作{{datas}}。 现在加载数据后,我可以删除 &lt;my-page&gt;&lt;/my-page&gt; 内容吗?

【问题讨论】:

    标签: angularjs angularjs-directive angularjs-scope


    【解决方案1】:

    你可以使用ng-if:

    <my-page ng-if="!datas"></my-page>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 2016-04-24
      • 1970-01-01
      相关资源
      最近更新 更多