大佬教程收集整理的这篇文章主要介绍了angularjs – 你在Angular中存储/创建模型的位置?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
customer.js:
function customer(){ this.firstName; this.lastName; } customer.prototype.getFullName = function(){ return this.firstName + ' ' + this.lastName; }
我还看到了工厂的使用:
customerFactory.js:
app.factory("customer",function(){ return function(){ this.firstName; this.lastName; this.getFullName = function(){ return this.firstName + ' ' + this.lastName; }; }; });
所以我的问题是,你在哪里存储模型以及为什么?这个人比其他人有更多优势吗?
为什么?因为这是Angular应用程序的构建方式.这样做允许您将它们注入您的控制器,指令等.如果您希望您的模型是Angular不可知的,那很好.它适合“端口和适配器”架构.稍后将它们作为工厂公开.将您的Angular-agnostic代码分离到一个单独的库中,然后将它们暴露出来以便以后注入:
app.factory("Customer",function(){ return Models.Customer; }); app.factory("Order",function(){ return Models.Order; });
以上是大佬教程为你收集整理的angularjs – 你在Angular中存储/创建模型的位置?全部内容,希望文章能够帮你解决angularjs – 你在Angular中存储/创建模型的位置?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。