Aug 4 2015 CoffeeScript Angular 使用CoffeeScript編寫Angular module filter factory controller module 1app = angular.module "app", [] 12var app; app = angular.module("app", []); filter 1234567891011app.filter "peopleSearch", ["$filter", ($filter) -> (data, text) -> return [] if not text data = data.filter((item) -> item["姓名"].search(text) > -1 or item["收治單位"].search(text) > -1 or item["醫療檢傷"].search(text) > -1 or item["救護檢傷"].search(text) > -1 ) data] 12345678910111213141516app.filter("peopleSearch", [ "$filter", function($filter) { return function(data, text) { if (!text) { return []; } data = data.filter(function(item) { return item["姓名"].search(text) > -1 || item["收治單位"].search(text) > -1 || item["醫療檢傷"].search(text) > -1 || item["救護檢傷"].search(text) > -1; }); return data; }; } ]); factory 123456789app.factory "people", ["$http", people = ($http) -> $http.get('http:////tonyq.org/kptaipei/api-20150628.php') .success((data) -> data ) .error((err) -> err )] 12345678910var people; app.factory("people", [ "$http", people = function($http) { return $http.get('http:////tonyq.org/kptaipei/api-20150628.php').success(function(data) { return data; }).error(function(err) { return err; }); } ]); controller 12345678910app.controller "MainController", ["$scope", "people", ($scope, people) -> $scope.type = "hospital" people .success((data) -> $scope.peoplelist = data ) .error((err) -> console.log "people-error: #{err}" )] 12345678910app.controller("MainController", [ "$scope", "people", function($scope, people) { $scope.type = "hospital"; return people.success(function(data) { return $scope.peoplelist = data; }).error(function(err) { return console.log("people-error: " + err); }); } ]); Newer SublimeText Plugin 提升Sass開發效率 Older CoffeeScript 擴充類別