Created
November 24, 2016 11:20
-
-
Save sibinx7/7d598425cd58954973f8d4c02cf99e2f to your computer and use it in GitHub Desktop.
Angular coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = angular.module 'myapp',[ | |
'ui.router' | |
'ngResource' | |
] | |
app.config ($stateProvider, $urlRouterProvider) -> | |
# For any unmatched url, send to /route1 | |
$urlRouterProvider.otherwise '/home' | |
$stateProvider.state 'home', | |
url: '/home' | |
templateUrl: 'partials/home.html' | |
controller: 'HomeController' | |
.state 'about', | |
url: '/about' | |
templateUrl: 'partials/about.html' | |
controller: ($scope) -> | |
$scope.items = [ | |
'A' | |
'List' | |
'Of' | |
'Items' | |
] | |
return | |
return | |
app.factory('BaseFactory',['$http',($http)-> | |
class BaseFactory | |
constructor: ($options) -> | |
]) | |
app.factory('GetYoutubeData',['$http','BaseFactory',($http,BaseFactory)-> | |
class GetYoutubeData extends BaseFactory | |
constructor: (options)-> | |
$YouTubeVideo: (id)-> | |
id = id.split('=') | |
@$http( | |
method:"GET" | |
url: 'http://gdata.youtube.com/feeds/api/videos/'+id[1]+'?v=2&alt=jsonc' | |
) | |
.success((data)-> | |
youtubedata = data.data | |
console.log youtubedata | |
$('#youtube').append('<span>Title: '+youtubedata.title+'</span>') | |
$('#youtube').append('<section><iframe width="560" height="315" src="https://www.youtube.com/embed/'+youtubedata.id+'" frameborder="0" allowfullscreen></iframe></section>') | |
) | |
]) | |
# --- | |
# generated by js2coffee 2.0.1 | |
class @BaseController | |
@register: (app, name) -> | |
name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1] | |
app.controller name, @ | |
@inject: (args...) -> | |
@$inject = args | |
constructor: (args...) -> | |
for key, index in @constructor.$inject | |
@[key] = args[index] | |
for key, fn of @constructor.prototype | |
continue unless typeof fn is 'function' | |
continue if key in ['constructor', 'initialize'] or key[0] is '_' | |
@$scope[key] = fn.bind?(@) || _.bind(fn, @) | |
@initialize?() | |
class HomeController extends BaseController | |
@register app | |
@inject '$scope','$http','GetYoutubeData' | |
initialize: -> | |
@$scope.title = "Home" | |
getData: (id) -> | |
@GetYouTubeData.YouTubeVideo(id) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment