小编use*_*841的帖子

angular -Which form type选择Model-Driven或Template Driven表单?

当我使用模型驱动的形式,如:

@Component({
  selector: 'my-app',
  template: `
  <p>
    <label>First Name:</label>
    <input type="text"  [ngModel]="user.firstName" required>
  </p>
  `,
  providers: [myService]
})
Run Code Online (Sandbox Code Playgroud)

当我使用模板驱动形式时,如:

 @Component({
      selector: 'my-app',
      template: `
      <p>
         <label>First Name:</label>
         <input type="text" formControlName="firstName">
      </p>
      `,
      providers: [myService]
    })
Run Code Online (Sandbox Code Playgroud)

我认为上面两件事都有相同的功能.所以,在开始新项目的时候,我觉得哪个更好?

model-driven-development angular

5
推荐指数
1
解决办法
1195
查看次数

推送http拦截器时的循环依赖

我正在使用 http 拦截器来拦截应用程序中的每个 http 请求。但我发现循环依赖: $http <- APIInterceptor <- $http <- $templateRequest <- $compile

这是我的服务代码:

mPosServices.factory('mosServiceFactory', function ($http, $rootScope, $cookies, $q) {
    return{
         refresh_token: function () {
            var refreshToken = $http({
                method: "get",
                url: "myservice/oauth/token?grant_type=refresh_token&client_id=restapp&client_secret=restapp&refresh_token=" + $cookies.get('refresh_token'),
            })
            return refreshToken;
        }
});

mPosServices.service('APIInterceptor', ['mosServiceFactory','$cookies',function (mosServiceFactory,$cookies) {
        var service = this;
        service.request = function (config) {
            if (!$cookies.get('access_token')) { //if access_token cookie does not exist
               mosServiceFactory.refresh_token().then(function (response) {
                    var date = new Date();
                    date.setTime(date.getTime() + (response.data.expiresIn * 1000));
                    $cookies.remove('access_token');
                    $cookies.put('access_token', …
Run Code Online (Sandbox Code Playgroud)

angularjs angular-http-interceptors

3
推荐指数
1
解决办法
3076
查看次数

如何指示有更多文本要滚动?

我正在制作一个网页并且我有很多文本,所以我制作了一个文本框,您可以使用Overflow: auto. 我的问题是我怎样才能更清楚地说明您可以滚动查看更多内容?目前,如果你不知道有更多文本,你可能不会滚动,所以我想添加一个小箭头作为滚动条,我可以只用 CSS 和 HTML 来做到这一点吗?

.container {
  width: auto;
  left: 25%;
  height: 60%;
  overflow: auto;
}
.text-box {
  position: absolute;
  top: 20%;
  width: 50%;
  overflow: auto;
  height: 70%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <div class="text-box">
    <h2 class="">I servizi per l'editoria scolastica</h2>
    <p>
      <h4>Progettazione e supporto alla progettazione di testi scolastici e universitari:</h4>
      <ul>
        <li>elaborazione di progetti editoriali e collane
          <li>consulenza e supervisione didattica
            <li>stesura apparati operativi
              <li>supporto e consulenza agli autori</ul>

      <h4>Progettazione grafica</h4>
      <ul>Analisi progetto editoriale e confronto …
Run Code Online (Sandbox Code Playgroud)

html css

3
推荐指数
1
解决办法
2847
查看次数

具有原始值的角按变化检测策略

可能是我误会了angular的changeDetection策略。

这是说明:

  • 我有2个同级组件(​​S1和S2)
  • 将这两个组件都视为在其上显示一些图形数据的小部件
  • 加载后,我想最初在两个组件上显示数据。(为此,我正在使用行为主题)
  • 我想从S1通知S2触发http服务调用。(我使用行为主题并在S1中单击按钮时调用.next。我正在S2中订阅相同的可观察对象以获取数据)
  • 我的S2组件已向onPush变更检测策略注册。
  • loading在进行HTTP服务调用时使用文本,然后在ngIf使用原始变量完成使用后删除文本this.loading=true/false

现在我的问题是,当App最初加载时,我可以loading...在S2小部件上看到文本,然后填充数据。

但是,当我单击notify siblingS1中的按钮时,它确实触发了服务调用,但是在http处理过程中,我看不到loading...文本。

这是S1的代码:

import { Component, OnInit } from '@angular/core';
import { MessagingService } from '../messaging.service';

@Component({
  selector: 'app-parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.css']
})
export class ParentComponent implements OnInit {

  constructor(private _sendMessage: MessagingService) { }

  ngOnInit() {
  }
  notifyChild() {
    this._sendMessage.notifySibling();
  }
}
Run Code Online (Sandbox Code Playgroud)

这是S2的代码:

import { Component, OnInit,ChangeDetectionStrategy ,ChangeDetectorRef} from '@angular/core';
import { MessagingService } from '../messaging.service';
import …
Run Code Online (Sandbox Code Playgroud)

typescript angular

2
推荐指数
1
解决办法
532
查看次数