AngularJS directives attributes access from the controller

后端 未结 6 470
梦如初夏
梦如初夏 2021-01-31 15:31

I am trying to access the attributes of a directive in the controller function. However, by the time I access it, it is undefined. I noticed that if I do a simple timer it works

6条回答
  •  醉酒成梦
    2021-01-31 16:31

    If you are accessing this value from your directive to insert in your view using a directive you can access this attribute using the $compile api and doing something like this

    var string = "
    " + scope.text + "
    "; $compile(string)(scope, function(cloned, scope){ element.append(cloned); });

提交回复
热议问题