Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript coffeescript角度函数调用_Javascript_Angularjs_Coffeescript_Haml - Fatal编程技术网

Javascript coffeescript角度函数调用

Javascript coffeescript角度函数调用,javascript,angularjs,coffeescript,haml,Javascript,Angularjs,Coffeescript,Haml,我有一个引用链接,我想分享,但我想知道我是否可以在一个已经是文字的函数调用中嵌入一个变量 在我的控制器中: $scope.get_share_link = (link) -> text = "http://www.whatever.com/share?u=" + encodeURIComponent(link) text 在我看来(咖啡脚本) 我能做这个吗?目前我得到http://www.whatever.com/share?u=link这当然不是解析链接老实说,我不确定你是否能

我有一个引用链接,我想分享,但我想知道我是否可以在一个已经是文字的函数调用中嵌入一个变量

在我的控制器中:

$scope.get_share_link = (link) ->
  text = "http://www.whatever.com/share?u=" + encodeURIComponent(link)
  text
在我看来(咖啡脚本)


我能做这个吗?目前我得到
http://www.whatever.com/share?u=link
这当然不是解析
链接

老实说,我不确定你是否能做到你所写的,但我很确定这是可行的

$scope.get_share_link = function(link) {
    return 'http://www.whatever.com/share?u=' + encodeURIComponent(link);
};
然后:


返回:
http://www.whatever.com/share?u=myurl

您需要有$scope.link\u url在某些地方

 $scope.link_url = "http://google.com"

 $scope.get_share_link = (link) ->
   "http://www.whatever.com/share?u=" + encodeURIComponent(link)

在此处查看工作示例

确定,已排序。我在看egghead.io视频,但我不知道过滤器会像函数调用一样使用!现在我觉得自己很傻

%a{:href=>"http://www.whatever.com/u={{link | encodeURIComponent}}"}

CoffeeScript插入双引号字符串,因此您应该仅在计划在字符串中使用变量或表达式的情况下使用它们。有趣的是,您的第二个字符串将是完美的,
”http://www.whatever.com/share?u=#{encodeURLComponent(link)}“
。但是,您的第一个字符串实际上应该是单引号。
link\u url
已经存在。它特定于每个条目,因此
link\u url
对于
ng repeat
的每个实例都是不同的。它不在全局范围内。同样,如果使用字符串插值,请仅使用双引号。
 $scope.link_url = "http://google.com"

 $scope.get_share_link = (link) ->
   "http://www.whatever.com/share?u=" + encodeURIComponent(link)
%a{:href=>"http://www.whatever.com/u={{link | encodeURIComponent}}"}