我是Angular(2,4)的新手.我试图连接到代理服务器.
proxy.config.json在项目根目录中添加
{
"/api/*": {
"target": "http://<server_ip_address>:<port>",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
Run Code Online (Sandbox Code Playgroud)
然后start在package.json中添加了代理配置
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
Run Code Online (Sandbox Code Playgroud)
现在在组件中我有一个连接到服务器的登录方法.
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AlertService, AuthenticationService } from '../services/index';
@Component({
moduleId: module.id.toString(),
templateUrl: 'login.component.html'
})
export class LoginComponent implements OnInit {
model: any = {};
loading …Run Code Online (Sandbox Code Playgroud) 我已经关注了node-and-npm-in-30-seconds.sh.
之前我曾经使用Yeoman和bower与NodeJS创建AngularJS应用程序.那次我用sudo来安装所有.
这就是我所遵循的
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install git-core
Run Code Online (Sandbox Code Playgroud)
最近我尝试创建一个AngularJS应用程序,但它没有正确创建.然后我发现在安装nodejs,yeoman和Bower时我不应该使用sudo.
我在这里搜索并找到了解决方案node-and-npm-in-30-seconds.sh.
所以首先我卸载了NodeJS
sudo apt-get remove nodejs
Run Code Online (Sandbox Code Playgroud)
然后按照链接中提供的第一个选项进行操作
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
Run Code Online (Sandbox Code Playgroud)
最后一个命令不起作用.这显示了
$ curl https://www.npmjs.org/install.sh …Run Code Online (Sandbox Code Playgroud) 从Web服务我得到一个JSON字符串.它可能会根据请求而有所不同.2个JSON结果是
结果1
[
{
"Key": 1,
"ID": 1,
"applicationId": "1",
"applicationName": "APP1"
},
{
"Key": 2,
"ID": 1,
"applicationId": "2",
"applicationName": "APP2"
}
]
Run Code Online (Sandbox Code Playgroud)
结果2
[
{
"OrgKey": 1,
"ID": 1,
"OrgID": "1",
"OrgName": "Org1"
},
{
"OrgKey": 2,
"ID": 4,
"OrgID": "6",
"OrgName": "Org2"
}
]
Run Code Online (Sandbox Code Playgroud)
我将如何在表格中显示?
在控制器js文件中我使用$http.get方法并在我放入的Success方法中
$scope.resultData = data;
Run Code Online (Sandbox Code Playgroud)
但在HTML中我将如何显示动态内容?
<table>
<thead>
<tr>
<th ng-repeat = "result in resultData">
<!-- Not the right way -->
<!-- Here I want to put the headers like "Key,ID" …Run Code Online (Sandbox Code Playgroud) 嗨我有一个像我的控制器中的跟随代码
myClientApp.controller('ListCtrl', function ($scope,$http,$cookieStore,$location, $routeParams) {
var data = {
"menus": {
"view": true,
"add": true,
"update": true,
"delete": true
},
"linkInfo": {
"labelColumn": "codeName",
"linkColumn": "lookupKey",
"urlInfo": "reference"
},
"resultList": [
"{\"lookupKey\":2,\"clientKey\":1,\"codeName\":\"Application.AppType\",\"codeValue\":\"ApplicationType2\",\"codeDesc\":\"##\",\"updatedBy\":null,\"internalCodeName\":\"Application.AppType\"}",
"{\"lookupKey\":3,\"clientKey\":1,\"codeName\":\"Application.Class\",\"codeValue\":\"Tier 1\",\"codeDesc\":\"Critical Application requiring immediate response in case of a disruption of Service\",\"updatedBy\":null,\"internalCodeName\":\"Application.Class\"}"
]
};
$scope.result = angular.fromJson(data.resultList);
alert($scope.result[0].codeName);
});
Run Code Online (Sandbox Code Playgroud)
它给了我不确定的.为什么?
我正在使用 AngularJS 应用程序。我有一个表格。提交时,我正在调用一个函数。我使用了 javascript try/catch/finally 块
$scope.save = function() {
try {
//Block of code to try
$scope.submit.text = "Submitting";
$scope.submit.disable = true;
$timeout(function(){
alert('successfully saved');
}, 5000);
}
catch(err) {
//Block of code to handle errors
}
finally {
alert("finally");
$scope.submit.text = "Submit";
$scope.submit.disable = false;
}
}
Run Code Online (Sandbox Code Playgroud)
我暂时使用了计时器。但稍后我可能会使用 AJAX 调用。问题是
finally 块在时间结束之前被执行。如何解决这个问题?
好的!AngularJS新手.这是我的控制器代码,用于检查值是未定义还是null.
var configId=$routeParams.confiId;
angular.isUndefinedOrNull = function(configId){ return angular.isUndefined(configId) || configId === null};
if(angular.isUndefinedOrNull) {
alert(configId);
alert("true");
} else {
alert("false");
}
Run Code Online (Sandbox Code Playgroud)
它总是警告true.所以我试着提醒configId.如果值在那里,它会警告该值,否则它将提示未定义.不会成为其他部分因为条件总是如此.这有什么不对?
我搜索了很多但找不到.
这是我的HTML
<li ng-repeat="tmp in list" ng-class="{active: $last}">
<a href="#{{tmp.url}}">{{tmp.text}}</a>
</li>
Run Code Online (Sandbox Code Playgroud)
它工作正常.但我想要的是最后一项ng-repeat,我不想添加<a>标签.我想用以下方式
<li ng-repeat="tmp in list" class="active">
{{tmp.text}}
</li>
Run Code Online (Sandbox Code Playgroud)
对于class="active"我添加使用ng-class="{active: $last}",但对于这没有<a>标签,如何添加?
angularjs ×5
javascript ×2
json ×2
angular ×1
angular-cli ×1
econnreset ×1
node.js ×1
ubuntu ×1