我在使用速度模板引擎的WebStorm中创建JavaScript模板时遇到了麻烦。
我想要的最终文件看起来像这样:
app.service('Name', ['$http', function($http) {
var singularUrlbase = apiurl + 'SingularName';
var pluralUrlbase = apiurl + 'PluralName';
this.get = function(id){
return $http.get( singularUrlBase + id );
}
}
我正在尝试使用此模板:
#set ( $url1 = 'singularUrlBase + "/" + id')
#set ( $url2 = "singularUrlBase + '/' + s.Id")
app.service('${NAME}', ['$http', function($http) {
var pluralUrlBase = apiurl + '$pluralName';
var singularUrlBase = apiurl + '$singularName';
this.get = function(id) {
return $http.get( $url1 );
};
}
问题是:
return $http.get ( $url1 )
而不是return $http.get( singularUrlBase + id );
$http
,WebStorm要求我设置$ http变量,但我不想这样做。答案 0 :(得分:2)
要转发jetbrains应用模板中的$
符号,您需要编写${DS}
,如docs
应该是这样的:
#set ( $url1 = 'singularUrlBase + "/" + id')
#set ( $url2 = 'pluralUrlBase + "/" + id')
app.service('${NAME}', ['${DS}http', function(${DS}http) {
var pluralUrlBase = apiurl + '$pluralName';
var singularUrlBase = apiurl + '$singularName';
this.get = function(id) {
if (this.get > 1) {
return ${DS}http.get( $url1 );
}
else {
return ${DS}http.get( $url2 );
}
}
}]);
文件名:young_people
pluralName:child
singularName:children
app.service('young_people', ['$http', function ($http) {
var pluralUrlBase = apiurl + 'child';
var singularUrlBase = apiurl + 'children';
this.get = function (id) {
if (this.get > 1) {
return $http.get(singularUrlBase + "/" + id);
}
else {
return $http.get(pluralUrlBase + "/" + id);
}
}
}]);
注意:你的语法有点不对,我修改了最后两行;)。