每当我点击我的提交按钮时都没有任何反应,目前我想让它做的就是打印出用户名和密码以测试绑定。 我能够与控制器通信并打印出我在控制器中创建的硬编码消息,似乎ng-click不会触发该方法。 任何帮助都会很棒, 谢谢:D
<section id="register-view" class="mainbar">
<section class="matter">
<div class="container">
<div class="row">
<label>{{vm.message}}</label>
<form class="register-form">
<label name="username_label"> Username: </label>
<input type="text" name="username" ng-model="vm.userDetails.username"/>
<br/>
<label name="password_label"> Password: </label>
<input type="text" name="password" ng-model="vm.userDetails.password"/>
<br/>
<button type="submit" class="btn btn-default" ng-click="vm.submitUserDetails()">Submit</button>
</form>
</div>
</div>
</section>
</section>
和控制器类
(function () {
'use strict';
angular
.module('app.register')
.controller('RegisterController', RegisterController);
RegisterController.$inject = ['$q', 'dataservice', 'logger'];
/* @ngInject */
function RegisterController($q, dataservice, logger) {
var vm = this;
vm.message = 'baass';
vm.userDetails = {
username: '',
password: ''
}
function activate() {
var promises = [submitUserDetails()];
return $q.all(promises).then(function () {
logger.info('Activated Dashboard View');
});
}
function submitUserDetails() {
console.log('Username: ' + vm.userDetails.username);
console.log('Password: ' + vm.userDetails.password);
}
}
})();
答案 0 :(得分:3)
您需要在控制器上下文中添加b_process.c
以使其在视图中可用,因为您只定义了#include <fcntl.h>
#include <sys/mman.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#define SHM_PATH "/instant_messaging"
#define SHM_SIZE 50
#define SEM_PATH "/sem_instant_messaging" //dddddddddd
char *sendbuff;
int main()
{
//sahred memory setting
//shm_unlink(SHM_PATH);
int shmfd;
shmfd = shm_open(SHM_PATH, O_CREAT | O_RDWR, S_IRWXU | S_IRWXG);
if (shmfd < 0) {
perror("In shm_open()");
exit(1);
}
int shm_size = SHM_SIZE;
ftruncate(shmfd,shm_size);
sendbuff = (char*) mmap(NULL, shm_size, PROT_READ | PROT_WRITE,
MAP_SHARED, shmfd, 0);
if (sendbuff == NULL) {
perror("In mmap()");
exit(1);
}
//semaphore setting
sem_unlink(SEM_PATH);
sem_t *sem1;
sem1 = sem_open(SEM_PATH, O_CREAT, S_IRUSR | S_IWUSR, 1);
while (1) {
printf("before wait %d\n", *sem1);
int status = sem_wait(sem1);
if (status != 0)
{
perror("in sem_wait");
}
printf("after wait %d\n", *sem1);
printf("%s", sendbuff);
scanf("%s", sendbuff);
sem_post(sem1);
}
}
的功能。您应该将其引用绑定到submitUserDetails
submitUserDetails
答案 1 :(得分:0)
该函数需要附加到$ scope
$scope.function submitUserDetails() {
console.log('Username: ' + vm.userDetails.username);
console.log('Password: ' + vm.userDetails.password);
}
答案 2 :(得分:0)
您的代码似乎存在一些问题,但最大的问题是这些函数实际上并未附加到“this”(vm
,因为您已在代码中调用它)。因此,范围无法访问它们,因为它们只能在RegisterController函数内访问。
要解决此问题,我会将此代码添加到您的函数底部:
this.activate = activate;
this.submitUserDetails = submitUserDetails;
同样,submitUserDetails()
应该返回一个承诺,不是吗?我希望这也会引起一些时髦的行为。