How to add Angular-enabled elements to DOM?

后端 未结 3 754
谎友^
谎友^ 2021-02-06 02:26

I would like to add some Angular-enabled DOM elements programmatically. Actually, I probably will need to add custom components. How can I do it?

Here\'s a trivial fiddl

3条回答
  •  清歌不尽
    2021-02-06 02:46

    As @Christopher Marshall pointed out, the simplest way to do this is using a repeating element and pushing a new item into scope on the button press.

    [HTML]

    {{test}}

    [JS]

    angular.module("main", []).controller("MyCtrl", function($scope) {
        $scope.add = function() {
            $scope.tests.push('New Message');
        };
    
        $scope.tests = ["Test Message","Test Message 2"];
    });
    

提交回复
热议问题