提前感谢您的帮助,我知道这可能是一个简单的问题,但我已经工作了一段时间,并没有弄清楚我做错了什么。
上下文信息
我试图为AngularJS实现一个简单的自定义指令。我的网页是用Mean.js样板建立的。为了为我的用户模块生成一个自定义指令,我通过执行以下命令使用了Yeoman生成器,
yo meanjs:angular-directive compareTo然后,我指定我希望在我的用户模块中的指令位置。这将生成一个带有示例自定义指令的指令目录。这是我的文件夹结构。http://imgur.com/SZvG706 (对不起,我还不能发布图片)
问题
我的理解是,这可以使用文本“这是h1指令”创建一个compareTo属性,还可以打印控制台消息,但是我在控制台中没有看到任何错误,也没有收到任何错误。
代码
下面是生成的比较指令文件。我唯一更改的是模板中的div到h1,并添加了控制台hi消息。
'use strict';
angular.module('users').directive('compareTo', [
function() {
return {
template: '<h1></h1>',
restrict: 'E',
link: function postLink(scope, element, attrs) {
// Compare to directive logic
// ...
console.log('hi');
element.text('this is the compareTo directive');
}
};
}
]);这是我的signup.client.view.html文件,在该文件中,我尝试使用比较到html标记来实现指令。
<section class="row" data-ng-controller="AuthenticationController">
<h3 class="col-md-12 text-center">Sign up with you email</h3>
<compare-to></compare-to>
<div class="col-xs-offset-2 col-xs-8 col-md-offset-4 col-md-4">
<form name="userForm" data-ng-submit="signup()" class="signin form-horizontal" novalidate autocomplete="off">
<fieldset>
<div class="form-group">
<label for="firstName">First Name</label>
<input type="text" required id="firstName" name="firstName" class="form-control" data-ng-model="credentials.firstName" placeholder="First Name">
</div>
<div class="form-group">
<label for="lastName">Last Name</label>
<input type="text" id="lastName" name="lastName" class="form-control" data-ng-model="credentials.lastName" placeholder="Last Name">
</div>
<div class="form-group">
<label for="organization">Organization Name</label>
<input type="text" id="organization" name="organization" class="form-control" data-ng-model="credentials.organization" placeholder="Organization Name">
</div>
<div class="form-group">
<label for="position">Position Title</label>
<input type="text" id="position" name="position" class="form-control" data-ng-model="credentials.position" placeholder="Position within organization">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" class="form-control" data-ng-model="credentials.email" placeholder="Email">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" class="form-control" data-ng-model="credentials.username" placeholder="Username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" class="form-control" data-ng-model="credentials.password" placeholder="Password">
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" name="confirmPassword" class="form-control" data-ng-model="confirmPassword" compare-to="credentials.password" placeholder="Confirm Password">
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-large btn-primary">Sign up</button> or
<a href="/#!/signin" class="show-signup">Sign in</a>
</div>
<div data-ng-show="error" class="text-center text-danger">
<strong data-ng-bind="error"></strong>
</div>
</fieldset>
</form>
</div>
</section>再次感谢!
发布于 2015-05-19 19:21:36
所以这个问题真的很傻。我所做的只是关闭我的节点服务器实例并重新运行咕噜,我以为我不需要这样做,因为每次您进行更改时,mean.js都会自动重新编译。但我想有时候你需要重新启动它。
https://stackoverflow.com/questions/30333643
复制相似问题