小编pan*_*s72的帖子

使用Angular中的其他字段发送FormData

我有一个有两个input text和一个的表格upload.我必须将它发送到服务器,但我有一些问题连接文件与文本.服务器期望这个答案:

"title=first_input" "text=second_input" "file=my_file.pdf"
Run Code Online (Sandbox Code Playgroud)

这是html:

<input type="text" ng-model="title">
<input type="text" ng-model="text">
<input type="file" file-model="myFile"/>
<button ng-click="send()">
Run Code Online (Sandbox Code Playgroud)

这是控制器:

$scope.title = null;
$scope.text = null;

$scope.send = function(){
  var file = $scope.myFile;
  var uploadUrl = 'my_url';
  blockUI.start();
  Add.uploadFileToUrl(file, $scope.newPost.title, $scope.newPost.text, uploadUrl);
};
Run Code Online (Sandbox Code Playgroud)

这是指令 fileModel:

  return {
restrict: 'A',
link: function(scope, element, attrs) {
  var model = $parse(attrs.fileModel);
  var modelSetter = model.assign;

  element.bind('change', function(){
    scope.$apply(function(){
      modelSetter(scope, element[0].files[0]);
    });
  });
}
};
Run Code Online (Sandbox Code Playgroud)

这就是服务 …

http multipartform-data form-data http-post angularjs

28
推荐指数
2
解决办法
8万
查看次数

ngStorage和$ window.localStorage之间的区别

ngStorage和$ window.localStorage有什么区别?什么时候使用一个而不是另一个?我必须选择其中一个用于Web应用程序.我必须保存配置文件用户和令牌的数据

javascript local-storage angularjs angular-directive ng-storage

7
推荐指数
2
解决办法
7500
查看次数

如果 URL 是手动编写的,Angular 会刷新应用程序

我正在使用 Angular 6,但我在更改路线时遇到了问题。如果我使用 routerLink 或 navigate() 方法浏览应用程序,它会正常工作,因为它只加载新模块(如有必要)。但是,例如,如果我在此链接中:localhost:8080/home,我单击 URL,取消“主页”,输入“配置文件”并按 Enter,它正确进入配置文件页面,但应用程序已重新加载(也是应用程序组件)。为什么?我想不通。这是我的路由:

const appRoutes: Routes = [
  { path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
  { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] },
  { path: 'login', component: LoginComponent },
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: '**', component: PageNotFoundComponent }
];

@NgModule({
  imports: [
    RouterModule.forRoot(appRoutes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

也许问题出在 auth-guard 上?

@Injectable()
export class AuthGuard implements CanActivate {

constructor(private store: …
Run Code Online (Sandbox Code Playgroud)

angular-routing canactivate angular angular-router

7
推荐指数
2
解决办法
5844
查看次数

切换css不适用于输入类型无线电

我有一个开关按钮.但它不适用于输入类型的无线电.如果我尝试使用复选框按钮就可以了.为什么?如何解决,维护无线电输入?

@charset "utf-8";
/* CSS Document */

/* ---------- GENERAL ---------- */

body {
	background: #4a4a4a;
	color: #151515;
	font: 100%/1.5em "Lato", sans-serif;
	margin: 0;
}

input {
    font-family: inherit;
    font-size: 100%;
    line-height: normal;
    margin: 0;
}

input[type="radio"] {
    box-sizing: border-box;
    padding: 0;
}

/* ---------- SWITCH ---------- */

.container {
	height: 64px;
	left: 50%;
	margin: -32px 0 0 -80px;
	position: absolute;
	top: 50%;
	width: 160px;
}

.switch {
	background: #fff;
	border-radius: 32px;
	display: block;
	height: 64px;
	position: relative;
	width: 160px; …
Run Code Online (Sandbox Code Playgroud)

html css input css3 checked

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

JSPDF 不添加带有在线 src 的图像

在 Web 应用程序中,我使用 JSPDF 将 html 转换为 pdf。一切正常,除了图像。过了一会儿,我注意到它添加了指向本地资源的图像;相反,它不会添加指向在线资源的图像,而是在图像的位置留下一个空白空间,就好像他期望它但无法加载它一样。

例如:<img src="img/house.jpg"/>正确添加。 <img src="https://myurl.com/house.jpg"/>未正确添加;有一个空白空间而不是图像。

我该如何解决?也许将图像暂时存储在本地?我尝试使用 addImage() 但它很难使用,不仅因为我改变了 pdf 的比例因子,而且主要是因为pdf 的内容是动态的,我不知道图像的大小或它们的确切大小位置。

html javascript pdf image jspdf

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

Limit rows in HTML5 textarea

I'm looking for a solution to a problem, but I'm not able to find it. It could be in AngularJS or in Javascript (then I'll translate it in AngularJS). The problem is that I have to limit the rows of a simple textarea. The attribute 'rows=x' of HTML5 limit just the view. I have to limit the lines. The problem is that even if graphycally the lines go down, the components looks at it as a unique line. The user …

html javascript textarea angularjs angularjs-directive

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

创建新阵列和清除长度之间的区别

如果我必须删除数组中的所有项目,使用new Array和之间有什么区别length = 0?在示例中,显然结果看起来相同.

function MyCtrl($scope) { 
    
    $scope.arrayData = ["1", "2", "3"];
    
    $scope.newArray1 = function(){
    	$scope.arrayData = new Array();
    }    
    
    $scope.newArray2 = function(){
    	$scope.arrayData = [];
    }
        
    $scope.lengthZero = function(){
    	$scope.arrayData.length = 0;
    }    
            
    $scope.populate = function(){
    	$scope.arrayData.push("1", "2", "3");
    }    
 }
 
 
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app ng-controller="MyCtrl">
Data:
</h2><br>
   <ul>
        <li ng-repeat="data in arrayData">{{data}}</li>
    </ul> 
    <button ng-click="newArray1()">New Array - 1st method</button>
    <button ng-click="newArray2()">New Array - 2nd method</button>
    <button ng-click="lengthZero()">Length = 0</button>
    
    <button ng-click="populate()">Populate</button>
</div>
Run Code Online (Sandbox Code Playgroud)

javascript arrays angularjs

4
推荐指数
1
解决办法
182
查看次数

JSPDF Autotable 打破行

在网络应用程序中,我使用 JSPDF Autotable 来构建 PDF。问题是数据是动态的(我将使用 AngularJS 1.x),因此行可以有不同的高度。

在某些情况下,Autotable 会中断页面​​的最后一行,继续到下一行。如何防止这种行为,并设置 Autotable 以获取最后一行(默认情况下会中断)并将其带到下一页?

这是我的代码:https://jsfiddle.net/9vgxvfkh/1/

我想我必须更改样式中的一些设置:

styles: {
    cellPadding: 1.5,
    overflow: 'linebreak',
    valign: 'middle',
    halign: 'center',
    lineColor: [0, 0, 0],
    lineWidth: 0.2 
},
pageBreak: 'always'
Run Code Online (Sandbox Code Playgroud)

但我尝试过,但没有成功。

PS:标题上的边距顶部是因为然后我将添加图像。

javascript pdf jquery jspdf jspdf-autotable

4
推荐指数
1
解决办法
1万
查看次数

$ state.go不是函数

我正在使用AngularJs做一个Web应用程序,我正在使用$ state进入应用程序.登录后,我想转到主页(状态'app.dashboard.home'的绝对状态'app.dashboard).

在这个页面中,有一个按钮可以进入另一个名为expense的视图(状态'app.dashboard.expense'的绝对状态'app.dashboard).但是当我点击按钮时,控制台会显示以下错误:

$ state.go不是函数

为什么?

这是路由:

angular.module('app')
.run(
['$rootScope', '$state', '$stateParams',
  function($rootScope, $state, $stateParams) {
    $rootScope.$state = $state;
    $rootScope.$stateParams = $stateParams;
  }
]
)
 .config(
['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider
    .otherwise('/app/authenticating/');

  $stateProvider
    .state('app', {
      abstract: true,
      url: '/app',
      templateUrl: 'common/mainApp.html'
    })

    .state('app.auth', {
      url: '/authenticating/',
      templateUrl: 'common/authenticating/authenticating.html',
      controller: 'authenticatingCtrl',
      resolve: {
        deps: ['$ocLazyLoad',
          function($ocLazyLoad) {
            return $ocLazyLoad.load({
              files: [
                'common/authenticating/controllers/authenticatingCtrl.js'
              ]
            }).then(function success(args) {
              console.log('success');
              return args;
            }, function error(err) {
              console.log(err);
              return err; …
Run Code Online (Sandbox Code Playgroud)

state angularjs angularjs-ng-click angular-ui-router

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

使用tap()代替map()RxJS和Angular

我有一个登录保护程序,基本上可以检查用户il是否已登录。如果已登录,则跳过登录并转到主页。我编写了这段代码,并且可以正常工作:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    return this.store.select(fromApp.isAuthenticated)
        .pipe(take(1),
            map(isAuthenticated => {
                if (isAuthenticated) {
                    this.router.navigate(['/home']);
                    return false;
                } else {
                    return true;
                }
            })
        )
}
Run Code Online (Sandbox Code Playgroud)

现在,由于我不必更改或编辑输出数据(isAuthenticated布尔值),所以我想:为什么不使用tap运算符?因此,我重新编写了代码:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    return this.store.select(fromApp.isAuthenticated)
        .pipe(take(1),
   HERE------> tap(isAuthenticated => {   <------ HERE
                if (isAuthenticated) {
                    this.router.navigate(['/home']);
                    return false;
                } else {
                    return true;
                }
            })
        )
}
Run Code Online (Sandbox Code Playgroud)

然后我去了Chrome,然后看到了黑页,情况就是这样:

observable rxjs redux angular rxjs6

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

如何在ngTable中过滤

使用Angular,我正在做http请求来获取数据.我添加了ngTable并用它来显示数据.它们正确显示在表格中,但我无法过滤,排序和删除它们.为什么?

JS:

      $scope.cancel = cancel;

function cancel(row, rowForm) {
  var originalRow = resetRow(row, rowForm);
  angular.extend(row, originalRow);
}

$scope.tableParams.reload().then(function(data) {
  if (data.length === 0 && $scope.tableParams.total() > 0) {
    $scope.tableParams.page($scope.tableParams.page() - 1);
    $scope.tableParams.reload();
  }
});

  $http.get('my_url')
.success(function(data, status) {
  $scope.data = data;

  $scope.tableParams = new ngTableParams({
    page: 1,            // show first page
    count: 10          // count per page
  }, {
    total: $scope.data.length, // length of data
    getData: function($defer, params) {
      // use build-in angular filter
      var orderedData = params.sorting() ?
        $filter('orderBy')($scope.data, …
Run Code Online (Sandbox Code Playgroud)

angularjs ngtable angular-filters

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