AngularJS并使用$timeout渲染模板

AngularJS并使用$timeout渲染模板,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我试图在1秒后呈现/返回此指令中的内容。尝试了多种方法,但似乎无法让它工作,我有一种直觉,它应该是超级容易。下面是我的代码示例。如果您能修改我的代码,我们将不胜感激 该指令: myApp.directive("helloWorld", ['$timeout', $timeout(function() { return { restrict: "E", template: '<h1>Hello World!</h1>' }; }, 1000)

我试图在1秒后呈现/返回此指令中的内容。尝试了多种方法,但似乎无法让它工作,我有一种直觉,它应该是超级容易。下面是我的代码示例。如果您能修改我的代码,我们将不胜感激

该指令:

myApp.directive("helloWorld", ['$timeout', $timeout(function() {
    return {
    restrict: "E",
    template: '<h1>Hello World!</h1>'
    };
}, 1000)]);
<hello-World/>
myApp.directive(“helloWorld”、[“$timeout”、$timeout(function()){
返回{
限制:“E”,
模板:“你好,世界!”
};
}, 1000)]);
调用上述指令的HTML局部视图代码:

myApp.directive("helloWorld", ['$timeout', $timeout(function() {
    return {
    restrict: "E",
    template: '<h1>Hello World!</h1>'
    };
}, 1000)]);
<hello-World/>

您可以使用指令控制器在超时后设置“show something variable”

myApp.directive("helloWorld", ['$timeout', (function($timeout) {
    return {
        restrict: "E",
        template: '<h1 data-ng-show="showData">Hello World!</h1>',
        controller: function($scope, $timeout) {
            $scope.showData = false;
            $timeout(function() {
                $scope.showData = true;
            }, 1000);
        }
    };
})]);
myApp.directive(“helloWorld”[“$timeout”,(函数($timeout){
返回{
限制:“E”,
模板:“你好,世界!”,
控制器:函数($scope,$timeout){
$scope.showData=false;
$timeout(函数(){
$scope.showData=true;
}, 1000);
}
};
})]);