0

I have a strange issue when using $compile(element)(scope) to bind some data to a dom element manually.

Please check the example code here.

In the example preview, when you click the button "Bind Template", the template is compiled with some data and rendered into a dom element. But when the button is clicked again, only the template is shown. Any idea what could be the problem here.

1 Answer 1

1

I don't know what you are trying to do doing it this way, but you should probably use a directive instead.

Here is your plunker working with a directive

app.controller('MainCtrl', function ($scope, $http, $templateCache, $compile) {
        $scope.name = 'World';
        $scope.result = '<empty>';

        $scope.bindTemplate = function () {
                $scope.item = {
                    CaseNumber: 1234,
                    CandidateName: 'Joe Smith',
                    CandidateEmail: '[email protected]',
                    IsActive: true
                }
        };

});

app.directive('caseDetails', function() {
    return {
        templateUrl: "template.html"
    }
})
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.