In a previous question, I inquired about the possibility of incorporating an attribute on a directive to allow for values to be passed in various formats, such as:
<my-directive att> //Evaluates to true
<my-directive att="true">
<my-directive att="false">
<my-directive att="51">
<my-directive att="51.234">
<my-directive att="'john smith'">
Alternatively, is it possible to use two-way binding with a variable on the controller's scope like this:
<my-directive att="SomeVariableOnControllerScope">
Standard "=" two-way binding doesn't work in this scenario as attempts to change something within the directive will result in an error when trying to write back to the variable. However, there has been mention of creating a new type of binding that can intelligently interpret the value being passed and determine whether it is a boolean, integer, float, or string enclosed in single quotes. This new binding would essentially "switch off" two-way binding if the value fits these criteria, ensuring nothing gets written back. If the value does not match any of these types, then standard two-way binding would be implemented.
I am unsure of how to approach this, but with some guidance, I believe I could figure it out. The main benefit of this concept is that we often need to output HTML from the server (for SEO purposes) without the necessity of binding to a controller. However, there are instances where two-way binding is required.
In essence, I am seeking a hybrid between "@" and "=" bindings that can dynamically ascertain whether a value or variable name is being supplied.
Any suggestions?