如何在没有ng-repeat,angularjs的情况下动态创建div?

时间:2016-02-29 12:31:53

标签: angularjs

我需要动态生成'div'而不需要ng-repeat和范围内的不同数据。

<div attribute={{atrb}}>{{name}}</div> (<- dynamic div).

控制器

$scope.GenerateDiv = function()
{
$scope.name = "praveen";
$scope.atrb = "01";
}

3 个答案:

答案 0 :(得分:3)

您可以使用ng-if$compile

答案 1 :(得分:2)

You can do it like

$scope.str = ''
for ( i = 0 ; i < arrayofdata ; i++ ){
  $scope.str += "<div>"+arrayofdata[0].ex+"</div>"
}


use Sanitize filter the following link contains log
https://docs.angularjs.org/api/ngSanitize

then create html like this
<div>
{{str | Sanitize}}
</div>

答案 2 :(得分:1)

如果是单 ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); SimpleModule module = new SimpleModule(); module.addSerializer(ZonedDateTime.class, new JsonSerializer<ZonedDateTime>() { @Override public void serialize(ZonedDateTime zonedDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeString(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ").format(zonedDateTime)); } }); objectMapper.registerModule(module); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); ,则使用div来控制其创建:

ng-if

如果不满足条件,则不会创建<div attribute="{{atrb}}" ng-if="name">{{name}}</div> 。当条件成立时,div将添加到您的DOM中。

如果您需要其中几个,请将参数存储在数组中并使用div