DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Sublime - AngularJS - Useful Auto-complete Snippets

Sublime - AngularJS - Useful Auto-complete Snippets

Ajitesh Kumar user avatar by
Ajitesh Kumar
CORE ·
Sep. 17, 14 · Interview
Like (0)
Save
Tweet
Share
6.17K Views

Join the DZone community and get the full member experience.

Join For Free
This article presents code samples and instructions to configure your Sublime editor to include ng (angular) scripts in auto-complete fashion. I found it important to get quickly started with my new angular apps. Based on following, you could define custom autocomplete snippets for all angular scripts.

Following are the steps to create snippet file for each angularjs script:

  • In Sublime Text Editor, go to Tools > New Snippet. A new untitled file consisting of following code would open:
<snippet>
	<content><![CDATA[
    Hello, ${1:this} is a ${2:snippet}.
    ]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>
  • Write following code within CDATA by replacing with code such as “Hello….”. The code would look like following.
<content><![CDATA[
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/$1.$2.$3/angular.min.js"></script>
]]></content>
  • Give an appropriate name within “TabTrigger” element. This would be name you would write in the editor followed by ctrl + “space bar” to autocomplete. I put the name such as “jsng”. The code would look like following:
<tabTrigger>jsng</tabTrigger>
  • Write the source type as “text.html” within scope element. The code would like following:
<scope>text.html</scope>
  • Once done with above steps, its time to save the file. The file name must end with .sublime-snippet. You could choose format such as filetype-triggername.sublime-snippet. For above, I used filename such as html-jsng.sublime-snippet
  • Close and re-open the sublime. Test by writing “js” and ctrl + “space bar” to see autocomplete option. You shall find your snippet displayed for selection. Once you select, you would see “/../”. This is left empty to put the version name. You could type in as 1.2.23 as per the current version and you are all set. You could however choose to create snippet for different versions separately.
Code Samples for Inclusion of AngularJS Scripts

The code below represents custom auto-complete snippet for following AngularJS libraries. Create snippet files for following scripts  based on above instructions.

  • angular.min.js: Type “jsng” & ctrl + “space bar” to include angular.min.js
  • angular-route.js: Type “jsngroute” & ctrl + “space bar” to include angular-route.min.js
  • angular-resource.js: Type “jsngresource” & ctrl + “space bar” to include angular-resource.min.js

Sublime Snippet for Inclusion of Angular.min.js

<snippet>
    <content><![CDATA[
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/$1.$2.$3/angular.min.js"></script>
]]></content>
    <tabTrigger>jsng</tabTrigger>
    <scope>text.html</scope>
</snippet>


Sublime Snippet for Inclusion of Angular-route.min.js

<snippet>
    <content><![CDATA[
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/$1.$2.$3/angular-route.min.js"></script>
]]></content>
    <tabTrigger>jsngroute</tabTrigger>
    <scope>text.html</scope>
</snippet>


Sublime Snippet for Inclusion of Angular-resource.min.js

<snippet>
    <content><![CDATA[
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/$1.$2.$3/angular-resource.min.js"></script>
]]></content>
    <tabTrigger>jsngresource</tabTrigger>
    <scope>text.html</scope>
</snippet>

Feel free to suggest/comment.


Snippet (programming) AngularJS

Published at DZone with permission of Ajitesh Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Securing VMs, Hosts, Kubernetes, and Cloud Services
  • Agile Scrum and the New Way of Work in 2023
  • How To Get Page Source in Selenium Using Python
  • How and Why You Should Start Automating DevOps

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: