在AngularJS应用程序中使用封装指令和路由的推荐方法是什么?(What is the recommended way to use an encapsulated directive and routing within an AngularJS app?)
我正在尝试使用AngularJs 1.5应用程序的最佳实践 。 已经关注了Todd Motto和John Papa的风格指南
问题是:我的应用程序使用ngRoute进行路由 。 所以这:
function RoutingConfig($routeProvider) { $routeProvider .when('/route1', { controller: 'Ctrl1 as vm', templateUrl: 'partials/route1.html', resolve: { myCoolService: myCoolService } // to abbreviate }) .when('/route2', { controller: 'Ctrl2 as vm', templateUrl: 'partials/route2.html' }) .otherwise({redirectTo: '/route1'}): } angular .module('myApp', ['ngRoute']) .config(RoutingConfig);
好。 到现在为止还挺好。
现在,让我们说,在我走向Angular 2的道路上, 我想采用指令方法封装所有内容 。 这样,我将使用AngularJS 1.5创建类似Web组件的东西。
如果我遵循正确的做法,我可以为我的route1创建一个指令,并直接为该指令定义一个控制器:
function MyCoolDirective() { var directiveDefObj = { controller: Ctrl1, controllerAs: 'vm', scope: { data: "=", }, bindToController: true, // isolated scope link: linkFnc // just declared to abbreviate }; return directiveDefObj; } angular .module('myApp') .directive('MyCoolDirective', MyCoolDirective);
那么, 我应该在哪里声明控制器? 在路由配置中? 在每个指令里面? 对我来说听起来有点冗余。
I'm trying to adopt best practices with an AngularJs 1.5 app. Already following Todd Motto's and John Papa's style guides
The thing is: my app has routes using ngRoute. So, this:
function RoutingConfig($routeProvider) { $routeProvider .when('/route1', { controller: 'Ctrl1 as vm', templateUrl: 'partials/route1.html', resolve: { myCoolService: myCoolService } // to abbreviate }) .when('/route2', { controller: 'Ctrl2 as vm', templateUrl: 'partials/route2.html' }) .otherwise({redirectTo: '/route1'}): } angular .module('myApp', ['ngRoute']) .config(RoutingConfig);
Ok. So far, so good.
Now, let's say that, in my road to Angular 2, I want to adopt the encapsulate everything in a directive approach. This way, I'll create something like web components, using AngularJS 1.5.
If I'm following the right practices, I could create a directive for my route1 and directly define a controller for that directive:
function MyCoolDirective() { var directiveDefObj = { controller: Ctrl1, controllerAs: 'vm', scope: { data: "=", }, bindToController: true, // isolated scope link: linkFnc // just declared to abbreviate }; return directiveDefObj; } angular .module('myApp') .directive('MyCoolDirective', MyCoolDirective);
So, where should I declare the Controllers? In the routing configuration? Inside each directive? Sounds a bit redundandt for me.
原文:https://stackoverflow.com/questions/37310516
满意答案
这可以通过使用
dcast
的data.table
来实现,它可以使用多个value.var
library(data.table) dcast(setDT(data), id~rater, value.var=c("x", "y"), sep=".") # id x.1 x.2 x.3 y.1 y.2 y.3 #1: 1 0 1 2 0 1 2 #2: 2 0 1 2 0 1 2
This can be achieved by using
dcast
fromdata.table
which can take multiplevalue.var
library(data.table) dcast(setDT(data), id~rater, value.var=c("x", "y"), sep=".") # id x.1 x.2 x.3 y.1 y.2 y.3 #1: 1 0 1 2 0 1 2 #2: 2 0 1 2 0 1 2
相关问答
更多R:你能指定reshape / cast中变量列的顺序吗?(R: Can you specify the order of variable columns from reshape/cast?)
从广泛到长的一组变量重塑(reshape from wide to long group of variables)
将R中的数据帧重新整形为宽格式[重复](Reshape data frame in R to wide format [duplicate])
R:从长到宽重新整形,重新整理列的顺序为原始列顺序[重复](R: Reshape from long to wide, order of reshaped columns as original column order [duplicate])
将列(长)的级别重新整理为新列(宽)(Reshape levels of a column (long) into new columns (wide))
重塑从长到宽格式[重复](Reshape from long to wide format [duplicate])
如何将具有两列的数据帧重新整形为宽格式?(How to reshape a data frame with two columns to wide format?)
撤消使用创建的任意数量的列重新整形(Undo reshape with arbitrary number of columns created [duplicate])
使用列名称中的id变量重新整形R [重复](Reshape with id-variable in column names R [duplicate])
在大多数列具有多个值的情况下,重新变换为宽到宽(Reshape long to wide where most columns have multiple values)
相关文章
更多AngularJS资源
2013年度最强AngularJS资源合集
【JavaScript】 2013年度最强AngularJS资源合集
AngularJs视频教程
RabbitMQ 路由模式(Routing)-使用 direct Exchange
使用bootstrap和metroui设计的微网站或手机app界面
手机app
微信Web APP应用
App与微信WebAPP
Angularjs 中文视频教程
最新问答
更多如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
maven中snapshot快照库和release发布库的区别和作用
arraylist中的搜索元素(Search element in arraylist)
从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
从iframe访问父页面的id元素(accessing id element of parent page from iframe)
linux的常用命令干什么用的
Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!