Skip to content

Instantly share code, notes, and snippets.

@sibinx7
Created November 24, 2016 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibinx7/7d598425cd58954973f8d4c02cf99e2f to your computer and use it in GitHub Desktop.
Save sibinx7/7d598425cd58954973f8d4c02cf99e2f to your computer and use it in GitHub Desktop.
Angular coffee
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