我在AngularJS显示用户信息写了一个小的指令,这是我写来完成代码,建议在AngularJS中用ng定义一个自定义指令吗?
angular.module('app').directive('userProfile', function(){
return {
templateUrl: "userProfile.html",
restrict: 'E',
}
});
而且我包括我的index.html
此指令,
<body ng-controller="myCtrl">
<user-profile><user-profile>
</body>
如果我想使用前缀ng-
来保持整个项目的统一结构,现在我已经尝试将.directive('userProfile'
声明更改为.directive('ngUserProfile'
这实际上是工作。
但是,我想知道是否建议模仿ng-
行为,如果有,是否有任何可以使用的最佳实践?
请帮忙!
在此先感谢, 戴夫
提供前缀的说明(**它不好的做法**)不要在自定义指令中使用'ng-'前缀,因为angular使用'ng-'约定,将来可能会与angular指令产生冲突。拥有像“ms-user-profile”这样的前缀的最佳实践 –