首先单击状态时,拥有"ui-view"属性的div将替换为该状态的"模板".但是,当我再次单击相同的状态时,其控制器不会重新加载.如何让此控制器再次加载?
例如,假设我有以下导航菜单:
<nav>
<a ui-sref="state1">State 1</a>
<a ui-sref="state2">State 2</a>
</nav>
Run Code Online (Sandbox Code Playgroud)
我的"ui-view"内容如下:
<div ui-view></div>
Run Code Online (Sandbox Code Playgroud)
我的州描述如下.当我点击导航菜单上的"状态1",我希望看到的文本"Ctrl 1 loaded"
上developer console
.如果这是第一次,那么我会观察那个文字.但是,当我重新单击相同的链接时,控制器没有再次加载,我无法看到"Ctrl 1 loaded"
控制台上显示的文本两次.
myApp.config(function ($stateProvider, $urlRouterProvider){
$stateProvider.state("state1", {
url: "#",
template: "<p>State 1</p>",
controller: "Ctrl1"
}).state("state2", {
url: "#",
template: "<p>State 2</p>",
controller: "Ctrl2"
});
});
Run Code Online (Sandbox Code Playgroud)
为什么?你有什么主意吗?
我面临一个问题,我不明白其中的原因.例外并没有给我一个理解问题的线索.
我想根据myArray中给出的数据在我的界面修改UILabel的内容.但是,作为我在函数"cellForRowAtIndexPath"中指定的行,程序将触发异常.
这个问题的原因是什么?
@property (strong, nonatomic) NSMutableArray *myArray; //
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[myArray addObject:@{@"field1": @"myfield1"}]
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
return self.myArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UILabel *myLabel = (UILabel *)[cell viewWithTag:100]; // myLabel is successfully created …
Run Code Online (Sandbox Code Playgroud) 我可以按如下方式创建一行:
var lineData = [{ "x": 50, "y": 50 }, {"x": 100,"y": 100}, {"x": 150,"y": 150}, {"x": 200, "y": 200}];
var lineFunction = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate("basis");
var myLine = lineEnter.append("path")
.attr("d", lineFunction(lineData))
Run Code Online (Sandbox Code Playgroud)
现在我想在此lineArray的第二点添加一个文本:
lineEnter.append("text").text("Yaprak").attr("y", function(d){
console.log(d); // This is null
console.log("MyLine");
console.log(myLine.attr("d")) // This is the string given below, unfortunately as a String
// return lineData[1].x
return 10;
Run Code Online (Sandbox Code Playgroud)
});
线的输出console.log(myLine.attr("d"))
:
M50,50L58.33333333333332,58.33333333333332C66.66666666666666,66.66666666666666,83.33333333333331,83.33333333333331,99.99999999999999,99.99999999999999C116.66666666666666,116.66666666666666,133.33333333333331,133.33333333333331,150,150C166.66666666666666,166.66666666666666,183.33333333333331,183.33333333333331,191.66666666666663,191.66666666666663L200,200
我可以用字符串格式获取路径数据.我可以将此数据转换回lineData数组吗?或者,在附加文本时是否还有其他简单的方法来重新生成或获取lineData?
请参考这个JSFiddle.
我一直在研究前端开发人员应该知道的工具.现在,我专注于HTML,我有一些问题,如下所示:
你对这些问题有任何意见和答案吗?
提前致谢..
在我的HTML文件中,我有一个<progress>
标记,我还将ui.bootstrap
依赖项注入我的控制器,如下所示:
var myApp = angular.module("myApp",["ui.bootstrap"]);
Run Code Online (Sandbox Code Playgroud)
在此配置中,AngularJS将转换<progress></progress>
为:
<div class="progress ng-isolate-scope" ng-transclude=""></div>
Run Code Online (Sandbox Code Playgroud)
当我删除"ui.bootstrap"它工作正常.您可以使用此示例JSFiddle进行演示.
当
它progress
变成<div class="progress ng-isolate-scope" ng-transclude=""></div>
它消失.据我所知,progress
ui.bootstrap 中有一个指令可以进行此转换.
那么,我怎样才能使这个进度条工作?或者,如何在progress
不删除依赖项的情况下禁用angular-ui 的指令?
提前致谢.
这是我的TextValidator类:
//TextValidator.h
#import <Foundation/Foundation.h>
@interface TextValidator : NSObject
- (BOOL) isValidPassword:(NSString *)checkPassword;
- (BOOL) isValidEmail:(NSString *)checkString;
- (BOOL) isEmpty:(NSString *)checkString;
@end
// TextValidator.m
#import "TextValidator.h"
@implementation TextValidator
- (BOOL) isEmpty:(NSString *)checkString
{
return YES;
}
- (BOOL) isValidPassword:(NSString *)checkPassword
{
return YES;
}
- (BOOL) isValidEmail:(NSString *)checkString
{
return YES;
}
@end
Run Code Online (Sandbox Code Playgroud)
这是我尝试在ViewController.m中初始化TextValidator类的方法:
//ViewController.h
#import <Foundation/Foundation.h>
@interface SignUpViewController : UIViewController <UITextFieldDelegate>
@end
//ViewController.m
#import "SignUpViewController.h"
#import "TextValidator.h"
@interface SignUpViewController ()
@property TextValidator *myValidator;
@end
@implementation SignUpViewController
- (void)viewDidLoad
{
[[self.myValidator …
Run Code Online (Sandbox Code Playgroud) 我想在我的项目中实现SocketIO.
我的项目的服务器端和客户端代码如下所示.
在客户端,有一个测试按钮,它向[self.afn post:@"/test" withParams:@{} completion:^(id obj{})]
服务器端发送一个post请求().self.afn是我的AFNetworking库包装类的实例对象.
服务器端使用函数捕获此post请求app.post('test', function(){...}
在此post请求处理程序中,我{hello: "world"}
在news
通道中发出data(),并且我希望在客户端在Objective CdidReceiveMessage
的SocketIO库的处理程序中捕获此数据.
我检查了一下,该按钮成功发送了post请求,服务器端成功处理了这个post请求并hello:"world"
在news
通道上发出data().但是,客户端不会在didReceiveMessage
处理程序上捕获此数据.
问题出在哪儿?你有什么主意吗?
服务器和客户端代码的详细信息如下:
ServerSide:
//server.js
var express = require('express');
var app = module.exports = express();
/* configure app ... */
var io = require('socket.io').listen(8090);
var mySocket;
io.sockets.on('connection', function (socket) {
mySocket = socket;
});
app.post("/test", function(req, res){
if(mySocket){
mySocket.emit('news', { hello: "world"});
}
});
Run Code Online (Sandbox Code Playgroud)
客户端:
//Client …
Run Code Online (Sandbox Code Playgroud) 我想将地图的中心初始化为自定义位置.这是我用于初始化的代码:
-(void)viewDidLoad{
[super viewDidLoad];
//mapView
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:41.0109
longitude:28.998
zoom:6];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
[self.mapView setCenter:CGPointMake(41.0109,28.998)];
}
Run Code Online (Sandbox Code Playgroud)
当我运行这段代码时,我看到了一张以格林威治为中心的地图,而不是我给相机的位置(41.0109,28.998).
当我调试代码并打印出self.mapView.camera的位置时,这是输出:GMSCameraPosition 0x17742ee0: target:(41.011, 28.998) bearing:0.000 zoomLevel:6.000 viewingAngle:0.000 lookAhead:0.000
.所以我成功设置了相机的位置,为什么它打开格林威治的位置?
编辑:
请注意,mapView是我添加到主页面的子视图(UIView),我试图设置和修改中心位置.这是我的故事板的快照:
当我尝试修改mapView时,我无法设置地图的位置.但是,如果我使用"视图"这是窗口的主视图,我可以成功地更改地图的中心.
原因是什么?
如何设置GMSMapView的启动位置?
编辑2 此项目的源代码可在此处找到
formControl
我有一个包含可编辑数据(将是对象)和只读数据(将是 HTML 上的静态文本)组合的数组。有没有办法在 Angular 中做到这一点?我也可以使用FormArrays
和FormGroups
添加这个静态文本,但感觉不对。让我用一个例子来详细说明这个问题:
假设我有一个 JSON 对象,如下所示:
itemArray = [{
title: 'fancy item', // not a member of the form (read-only)
quantity: 0 // member of the form (editable)
},
{
title: 'weird item', // not a member of the form (read-only)
quantity: 1 // member of the form (editabe)
}
]
Run Code Online (Sandbox Code Playgroud)
我使用 FormArrays 作为quantity
项目字段。
this.formItems = new FormArray([
new FormGroup(
{
quantity: new FormControl(1, Validators.required),
title: new FormControl('Fancy item') // Readonly …
Run Code Online (Sandbox Code Playgroud) ios ×4
objective-c ×4
angularjs ×2
alloc ×1
angular ×1
angular-ui ×1
d3.js ×1
formarray ×1
formgroups ×1
frontend ×1
gmsmapview ×1
html ×1
html5 ×1
javascript ×1
node.js ×1
progress ×1
socket.io ×1
svg ×1
uitableview ×1