我想将angular plain vanilla JS代码转换为Typescript。请考虑以下代码片段:
app.someController = function ($scope) {
// var $scope.Data = null;
var $scope.Data: SomeCollection = null;
我正在将数据附加到范围。我希望它是SomeCollection类型。我该怎么办?
答案 0 :(得分:1)
我正在将数据附加到范围。我希望它是SomeCollection类型。我该怎么办?
类型注释需要进入范围。所以:
@tag = Tag.where(name: tag_name_string_from_user)
if @tag.nil?
@tag = Tag.new(name: tag_name_string_from_user)
@tag.save
@recipe.tags << @tag
render 'show.html.erb'
end
答案 1 :(得分:0)
interface MyScope : ng.IScope{
Data: SomeCollection
}
app.someController = function ($scope : MyScope) {
}