Cha*_*ies 1 coffeescript angularjs
我这里有一个简单的角度应用程序
<div ng-app="WhereToMeet" ng-controller="MapCtrl">
<leaflet shape="shape"></leaflet>
<button ng-click="clicked()">Clicked</button>
</div>
app = angular.module("WhereToMeet", [])
app.directive "leaflet", ->
restrict: "E"
replace: true
transclude: true
template: "<div id=\"map\"></div>"
scope:
shape: "=shape"
link: (scope, element, attrs, ctrl) ->
scope.$watch attrs.shape,( (newValue, oldValue) ->
watched newValue
), true
watched = (newValue) ->
alert newValue
@MapCtrl = ($scope) ->
clicked = (clicked) ->
$scope.shape = "Clicked"
alert "clicked"
Run Code Online (Sandbox Code Playgroud)
我有一个JSFiddle http://jsfiddle.net/charliedavi/bezFB/22/但它不会运行.真奇怪.我认为这是我的咖啡脚本的错误,但我看不到它
错误:
Uncaught SyntaxError: Unexpected string fiddle.jshell.net:22
Uncaught Error: No module: WhereToMeet
Run Code Online (Sandbox Code Playgroud)
在纯JS中
var app;
app = angular.module("WhereToMeet", []);
app.directive("leaflet", function() {
var watched;
({
restrict: "E",
replace: true,
transclude: true,
template: "<div id=\"map\"></div>",
scope: {
shape: "=shape"
},
link: function(scope, element, attrs, ctrl) {
return scope.$watch(attrs.shape, (function(newValue, oldValue) {
return watched(newValue);
}), true);
}
});
return watched = function(newValue) {
return alert(newValue);
};
});
this.MapCtrl = function($scope) {
var clicked;
return clicked = function(clicked) {
$scope.shape = "Clicked";
return alert("clicked");
};
};
Run Code Online (Sandbox Code Playgroud)
我不知道咖啡脚本但有角度.我只是想解决它.;-)
使用此角度引导手动初始化角度
angular.bootstrap document, ['WhereToMeet']
生成的javascript代码在另一个范围内.您必须通过将-b
参数添加到coffeescript编译器或通过显式导出函数来解决此问题
root = exports ? this
root.clicked = ->
alert "clicked"
$scope.shape = "Clicked"
Run Code Online (Sandbox Code Playgroud)
现在正在摆弄这里