【发布时间】:2014-03-03 06:32:15
【问题描述】:
我是 Angular 新手,正在尝试创建我的第一个指令。
这是一个例子:
isrcorderapp.directive "isrcrow", () ->
restrict:'A'
controller: 'isrcorders'
template: '<td><input id="artist" ng-model="{{artist}}"/></td>
<td><input id="title" ng-model="{{title}}"/></td>
<td><select id="isrctype" ng-model="{{isrctype}}" ng-options="s.type for s in recordingTypes" class="ng-pristine ng-valid"></select></td>
<td><input id="duration" ng-model="{{duration}}"/></td>
<td><input id="year" ng-model={{year}}/></td>
<td><input type="button" value="Add ISRC" ng-click="AddIsrc()" class="btn btn-small btn-success" />
<input type="button" value="Delete" ng-click="RemoveIsrc()" class="btn btn-small btn-danger" />
</td>'
replace: false
scope:
artist:'@'
title:'@'
isrctype:'@'
duration:'@'
year:'@'
link: (scope,element,attr) ->
在我在元素中添加范围和 ng-model 之前,该指令一直有效。
这是添加之前的一个工作示例:
http://plnkr.co/edit/oxXZlsFIDAbBCYMDOYMH?p=preview
我想将fields(artist.title,isrcType...) 的值添加到范围对象,但在加载网页时我不断收到错误:
错误:[$parse:syntax]
我该如何解决这个问题?我在这里做错了什么?
【问题讨论】:
标签: angularjs angularjs-directive