无法在视图中访问范围变量

时间:2016-11-22 10:55:43

标签: angularjs codeigniter angularjs-scope

我是angular的新手。我无法在视图中访问范围变量。

控制器

devices->inputStream[i]

查看

struct io *devices;
devices = malloc(sizeof(*devices));  

devices->inputStream = malloc(sizeof(struct inStream *) * numDevices);

for(int i = 0; i < 4; i++) {  
    devices->inputStream[i] = malloc(sizeof(struct inStream));  
}

任何人都请帮助我

5 个答案:

答案 0 :(得分:0)

相同的代码可以使用 DEMO

您可以使用ng-bind-html-unsafe指令绑定html数据。

<div ng-controller="MyCtrl">
    <pre ng-bind-html-unsafe="value"></pre>
</div>

<强> DEMO

答案 1 :(得分:0)

定义

$scope.values = {thisValue:value}

然后是int html

{{values.thisValue}}

答案 2 :(得分:0)

https://jsfiddle.net/robert07ravikumar/m3n450h1/

角色代码

function MyController($scope) {
    $scope.printName = function(name) {
       $scope.namePrint = name;
    };
}

HTML CODE

<div class="well" ng-controller="MyController">

    <button ng-click="printName('robert ravikumar')">print name</button>

    <span>{{namePrint}}</span>
    </div>

将值赋值给范围变量(namePrint)并使用范围变量双括号在视图中显示它

答案 3 :(得分:0)

您需要调用$scope.$digest()来告诉angular重新处理视图。即:

$scope.getData = function (val) {   
  alert(val)  
  $scope.value= val;
  $scope.$digest();
}

答案 4 :(得分:-1)

HTML

<div ng-app="myApp" ng-controller="myCtrl">

    <div class="row">
        <div class="col-lg-2"><input type="text" ng-model="value" /></div>
        <div class="col-lg-2"> <input type="button"  value="GetData " ng-click="GetData('myNewValueProvidedFromHtml')" /></div>

    </div>


  <span ng-bind="value"></span>
</div>

var myApp = angular.module("myApp", []);


myApp.controller('myCtrl', function ($scope) {

    $scope.value = "my value";

    $scope.GetData = function (newValue) {
        $scope.value = newValue;

    }


});