Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
从角度检索像{{cat}}这样的值,有没有办法设置一个值,如果没有值在$scope?
$scope
不确定你是否想做这样的事情:
<div ng-init="cat = cat || 'Tom Cat'">{{cat}}</div>
如果您不想初始化而只想显示它:
<div>{{cat || "Tom Cat"}}</div>
你也可以使用
$scope.cat ||= "Tom Cat"
在您的控制器中。