1

I am trying to render/return the content within this directive after 1 second. Tried multiple ways of doing this but can't seem to get it working and I have a gut feeling that it should be super easy. Below is an example of my code. Corrections to my code would be greatly appreciated!

The Directive:

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

HTML-partial view code Calling the above Directive:

<hello-World/>

1 Answer 1

3

You could use the directives controller to set a "show something variable" after a timeout

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);
        }
    };
})]);

http://jsfiddle.net/2om8ybhy/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.