在Angular中,我可能有一个看起来像这样的表单:
<ng-form>
<label>First Name</label>
<input type="text" ng-model="model.first_name">
<label>Last Name</label>
<input type="text" ng-model="model.last_name">
</ng-form>
Run Code Online (Sandbox Code Playgroud)
在相应的控制器中,我可以轻松地观察对该表单内容的更改,如下所示:
function($scope) {
$scope.model = {};
$scope.$watch('model', () => {
// Model has updated
}, true);
}
Run Code Online (Sandbox Code Playgroud)
这是JSFiddle上的一个Angular示例.
我无法弄清楚如何在Angular中完成同样的事情.显然,我们不再拥有$scope$ rootScope.当然有一种方法可以实现同样的目的吗?
我创建了一个生成Twitter按钮的指令.由于这些按钮上的范围变量可能会发生变化,因此我需要在按钮发生时重建它.目前,我正在使用jQuery empty()链接元素并重建按钮.
app.directive 'twitterShare', ($timeout, $window) ->
restrict: 'E'
template: '<a href="https://twitter.com/share" class="twitter-share-button" data-text="{{ text }}" data-url="{{ url }}">Twitter</a>'
scope:
text: '@'
url: '@'
link: (scope, el, attrs) ->
scope.$watch 'text', -> rebuild()
scope.$watch 'url' , -> rebuild()
rebuild = ->
$(".twitter-share-button").remove()
tweet = $ '<a>'
.attr 'href', 'https://twitter.com/share'
.attr 'id', 'tweet'
.attr 'class', 'twitter-share-button'
.attr 'data-lang', 'en'
.attr 'data-count', 'none'
.text 'Tweet'
el.prepend tweet
tweet.attr 'data-text', scope.text
tweet.attr 'data-url', scope.url
$window.twttr.widgets.load()
Run Code Online (Sandbox Code Playgroud)
有没有办法让指令完全重新渲染模板?
有没有办法控制段上的滚动?在我的情况下,滑块和段相互依赖,当您滑动幻灯片时,溢出段不会滑动,但会正确选择活动段
我的视图和控制器代码:
<ion-segment scrollable mode="md" (ionChange)="segmentChanged()" [(ngModel)]="segment" color="warning">
<ion-segment-button mode="md" value="0">
<p>Description</p>
</ion-segment-button>
<ion-segment-button mode="md" value="1">
<p>Interconnections</p>
</ion-segment-button>
<ion-segment-button mode="md" value="2">
<p>Declensions</p>
</ion-segment-button>
</ion-segment>
<ion-slides (ionSlideDidChange)="slideChanged()" pager="true">
<ion-slide>
First
</ion-slide>
<ion-slide>
second
</ion-slide>
<ion-slide>
third
</ion-slide>
</ion-slides>
Run Code Online (Sandbox Code Playgroud)
segmentChanged() {
this.slider.slideTo(this.segment);
}
async slideChanged() {
this.segment = await this.slider.getActiveIndex();
}
Run Code Online (Sandbox Code Playgroud)
该段本身工作正常,但滑动时,活动段位于屏幕后面。
我上面有这个模型,我想删除标题.或者重命名它.实际上匹配编号本身就是这个模型的标题.所以我需要以下选项之一:
我的模特:
class Match(Page):
match_number = models.PositiveSmallIntegerField(blank=True)
team_1 = models.ForeignKey(
TeamRooster,
null=True, blank=True,
on_delete=models.SET_NULL,
related_name="+",
)
team_1_color = ColorField(default='#ff0000', blank=True)
team_1_score = models.PositiveSmallIntegerField(blank=True)
team_2 = models.ForeignKey(
TeamRooster,
null=True, blank=True,
on_delete=models.SET_NULL,
related_name="+",
)
team_2_color = ColorField(default='#0066ff', blank=True)
team_2_score = models.PositiveSmallIntegerField(blank=True)
match_starts_at = models.DateTimeField()
parent_page_types = ['Matches']
content_panels = [
FieldPanel('title'),
FieldPanel('match_number', classname="6"),
FieldPanel('match_starts_at', classname="6"),
MultiFieldPanel([
FieldPanel('team_1', classname="12"),
FieldPanel('team_1_color', classname="6"),
FieldPanel('team_2_score', classname="6"),
], heading="Team 1"),
MultiFieldPanel([
FieldPanel('team_2', classname="12"),
FieldPanel('team_2_color', classname="6"),
FieldPanel('team_2_score', classname="6"),
], heading="Team 2"),
]
Run Code Online (Sandbox Code Playgroud) 我确实试图找到问题的答案,但不知道该怎么办。我发现了以下问题,但他们没有帮助我。问题1、问题2、文档
\n\n我使用的不同函数得到了不同的值。有时None值
\nTypeError: Object of type \'method\' is not JSON serializable
有时\nAttributeError: \'str\' object has no attribute \'status_code\'和\n而这个
\nTypeError: \'method\' object is not iterable
但我仍然没有找到解决我的问题的解决方案。\n这是我的页面模型,它InlinePanel从另一个类获取一些数据:
class ScreencastPage(Page):\n content_panels = Page.content_panels + [\n InlinePanel(\n \'groupstage_screencast_relationship\', label="Choose Teams",\n panels=None, max_num=2),\n ]\n\n parent_page_types = [\'home.HomePage\']\n\n def matches(self):\n matches = [\n n.match for n in self.groupstage_screencast_relationship.all()\n ]\n\n return matches\n\n def serve(self, request):\n if request.is_ajax():\n # TODO Convert self.mathes …Run Code Online (Sandbox Code Playgroud)