0

I want create kendo control using angularJs for that bind an expression inside input field as a attribute name.

Code:

<input {{controllabelName}} />

The above code is not working. if i will use ng-bind then it's binding value to that input not as an attribute name.

please anyone help me to achieve this.

5
  • if you want to add attribute to the element then you can use angular directive. in directive you can add the attributes to the element. Commented Mar 16, 2016 at 9:35
  • can you provide any example for this using directive Commented Mar 16, 2016 at 9:54
  • i have add the example as answer, also i include plunker link Commented Mar 16, 2016 at 13:09
  • What you wanted to achieve here, you can't add attribute dynamically using {{}} directive. We can help with better alternative approach by understanding a goal... Commented Mar 16, 2016 at 13:11
  • @PankajParkar Actually i want to create kendo control using angular. for example i want to create Kendo AutoComplete textbox. that would be <input kendo-auto-complete />, here the kendo-auto-complete i will get dynamically. i hope i explained well. Commented Mar 17, 2016 at 7:32

2 Answers 2

2

HTML

<!DOCTYPE html>
<html ng-app='exampleApp'>

<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js"></script>
<script src="script.js"></script>
</head>

<body>
<input type="text" customdirective/>
</body>
</html>

script.js

angular.module('exampleApp', [])
.directive('customdirective', function() {
  return {
   restrict: 'A',
   link: function(scope, ele, attr) {
    ele.attr('test', 'test');
  }
 }
})

Plunker link

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer but this is way wont work, what i want to achieve. Actually i want to create kendo control using angular. for example i want to create Kendo AutoComplete textbox. that would be <input kendo-auto-complete />, here the kendo-auto-complete i will get dynamically. i hope i explained well.
get the dynamic value and pass the value to scope. you can access the scope values inside the directive using the scope argument which is passed in the link function.
if you are get the dynamic value from web service or some external system which have some delay in response then you may need to watch the scope value inside the directive. so if the scope value change directive will update.
0

Use ng-model if you want value to be bind otherwise just any attribute name :

<input ng-model="controllabelName" />

1 Comment

ng-model also will bind a value to the field not as a attribute. for example controllabelName is "customer" i want input field is <input customer/>. I think here i explained correctly. Please let me know if you need more details.

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.