如何在不使用指令的情况下在 angularjs 中动态添加元素?

How to add element dynamically in angularjs without using directive?

首先,我是新来的Angularjs,英语不好

我尝试使用directive添加<li>,下面link是我第一个目的的完成结果。

Add element using directive

其次是将值从 Controller 传递到 directive 或从 directive 传递到 Controller,称为 two-way binding

但是在这一步中,我不知道如何使用@=和'&'。

我猜是因为在directive中使用了directive

在我的原始代码中,我的模式是由 directive 组成的,所以 button directive 似乎无法从 Controller.

中获取值

很抱歉,我无法向您展示我自己的代码,因为我不知道如何在 fiddle.

中制作许多 directive

.

.

我想知道有什么方法可以在不使用 directive 的情况下动态添加元素。

无论您提出什么建议,例如 link、文档或其他内容,都会对我有很大帮助。

请稍微注意一下。谢谢你。祝你有美好的一天!

你可以选择 ng-include

Fetches, compiles and includes an external HTML fragment.

这可能会有帮助。

您可以使用 javascript 如下实现此目的。

https://jsfiddle.net/u08pa50z/

angular.module('myApp', [])


.controller('myCtrl', ['$scope', function($scope) {
    $scope.count = 0;
    var el = document.createElement("ul");
    el.style.width="600px";
    el.style.height="500px";
    el.style.background="green";

    var parent=document.getElementById("sib");    
    parent.appendChild(el);





    $scope.myFunc = function() {

        var ch = document.createElement("li");      
            el.appendChild(ch);

    };
  }]);