我有这样的指示:
<simperium-auth method="create"></simperium-auth>
我已经在范围中添加了方法,因此我可以像这样引用它:
<form ng-attr-name="{{method}}" ng-submit="auth(method)" novalidate>
这很有效。但是,我想将它添加为另一个变量的一部分,就像这样(虽然,这不起作用):
{{[method].email.$error.serverMessage}}
以下完整指令:
<div ng-controller="auth">
<h3 ng-show="method == 'create'">Create account</h3>
<h3 ng-show="method == 'login'">Login</h3>
<form ng-attr-name="{{method}}" ng-submit="auth(method)" novalidate>
<div>
<input name="username" ng-model="username" type="email" required placeholder="Your e-mail">
<div class="helper" ng-show="{{method}}.username.$error.required"><p>Provide an email-adress</p></div>
<div class="helper error" ng-show="{{method}}.username.$error.email"><p>This is not a valid email</p></div>
<div class="helper error" ng-show="{{method}}.username.$error.serverMessage"><p>{{this['method'].email.$error.serverMessage}}</p></div>
</div>
<div>
<input name="password" ng-model="password" type="password" required placeholder="Select a password">
<div class="helper" ng-show="{{method}}.password.$error.required"><p>Povide a password</p></div>
</div>
<input type="submit" value="{{method}}">
</form>
</div>
答案 0 :(得分:0)
<p ng-bind="{{method}}.username.$error.serverMessage"></p>
ng-bind填充标记。