A
A
abusabir2015-12-25 23:12:34
JavaScript
abusabir, 2015-12-25 23:12:34

Why is the model passing in angular.js not parsed?

A simple example: I create my own directive, in the template of which there is a simple input.
In order to use the directive repeatedly (as a component), I want to bind it each time to a different model when using it.
I do something like this
<form ng-controller="ForTosterCtrl as tosterCtrl">
...

<my-directive icon="home" placeholder="Начало" model="tosterCtrl.startPoint"></my-directive>

When creating a directive:
scope: {
                icon: '@',
                placeholder: '@',
                model: '='
            }

It seems to be nothing complicated. But in the directive template:
<input ng-model="{{model}}" placeholder="{{placeholder}}"/>

this option does not work and throws an error on the ng-model directive
Syntax Error: Token '{' invalid key at column 2 of the expression [{{model}}] starting at [{model}}].

It is clear that something is wrong, but I did not understand what.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-12-25
@abusabir

well, because such syntax is forbidden for expressions. Read the documentation. ng-model uses two-way binding, so the parentheses (sugar for value interpolation) need to be removed.
ps I highly recommend reading the documentation for the tools you use. Well, or at least take video courses.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question