我有两个指令,resource
和formajax
. 他们来了:
资源
resource.coffee(部分)
(...)
($http, $location, $compile) ->
restrict: "E"
templateUrl: templateUrl
scope:
action: "@"
transclude: true
link: (scope, element, attributes) ->
(...)
资源.html
<div class="resource">
<style type="text/css">
.resource .new-record {
padding: 10px;
}
</style>
<button class="button" ng-click="addRecord()">+ Dodaj wiadomość</button>
<div class="new-record" ng-show="showAddForm">
<formajax action="{{action}}" />
</div>
<div ng-transclude></div>
</div>
和formajax
formajax.coffee(部分)
(...)
($http, $location) ->
restrict: "E"
scope:
action: "@"
title: "@"
formStatus: "="
additionalFields: "="
onData: "&"
templateUrl: templateUrl
link: (scope, element, attributes) ->
(...)
formajax.html
<form method="post" action="{{action}}" role="form" class="form-ajax">
<fieldset>
<legend>{{title}}</legend>
<div ng-bind-html-unsafe="form"></div>
<button type="button" ng-click="submit()" class="btn button">Wyślij</button>
</fieldset>
</form>
自举
这就是我开始一切的方式:
<resource action="/api/messages/">
问题是,在链接时action
没有传递给,而不是. 它在里面,它最终是可用的,但我想它稍后会绑定,为时已晚,无法与期望的价值联系起来。也许和异步加载会导致问题,使某些绑定不可能或未处理?formajax
undefined
/api/messages/
$watch
scope.action
resource
formajax
templateUrl