[英]Angularjs, how to structure my code across multiple files
I'm new to AngularJS and have a question regarding the structure of AngularJS. 我是AngularJS的新手,并且对AngularJS的结构有疑问。
Here is a simple working Plunker example I was working on, which displays the map. 这是我正在研究的一个简单的工作Plunker示例 ,它显示了地图。
So my question is: 所以我的问题是:
how do you separate out <mapbox callback="callback"></mapbox>
if I want to create a file in the view folder instead of putting it into app.js? 如果我想在视图文件夹中创建文件而不是将其放入app.js,如何分隔<mapbox callback="callback"></mapbox>
?
I have tried creating a show.html file inside of my view folder and pasted that line of code, but it didn't work. 我尝试在视图文件夹中创建一个show.html文件,并粘贴了该行代码,但是没有用。
Should I change 'template': '<mapbox callback="callback"></mapbox>'
to 我应该将'template': '<mapbox callback="callback"></mapbox>'
更改为
templateUrl: 'views/show.html'
? templateUrl: 'views/show.html'
吗?
Your help is greatly appreciated. 非常感谢您的帮助。
Yes. 是。 I slightly modified your plunker to show how can you can do it. 我稍加修改了您的pl头,以显示您如何做到这一点。
http://plnkr.co/edit/Fpst5cd6gfIh30eOk447 http://plnkr.co/edit/Fpst5cd6gfIh30eOk447
Basically, what I did there was to create a new html file, name it mapbox.html
and paste the html template there from app.js. 基本上,我要做的就是创建一个新的html文件,将其命名为mapbox.html
然后将来自app.js的html模板粘贴到该文件中。 Afterwards, I edited the app.js config block to use the templateUrl
property pointing to the new file above and deleted the template
property one, et voilà! 后来,我编辑的app.js配置块使用templateUrl
属性指向上述新文件和删除template
特性之一,等瞧!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.