角度不渲染< br>在我的json中 [英] Angular not rendering <br> in my json

查看:129
本文介绍了角度不渲染< br>在我的json中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用angular,它将在页面上显示json的元素.它不起作用.我想做的很简单.但它不起作用

I am trying to use angular which displays on the page the element from the json. Its not working. What I am trying to do is pretty straightforward. But its not working

这是我的代码:

http://jsfiddle.net/sqxmyrcj/1/

(function(){
    var app = angular.module('store', []);

    app.controller('PortfolioController',function(){
        this.product = gem;
    });

    var gem = 
            {
        name: 'TEmp',
        aboutme: 'A Computer Science student at <br>The University Canada.<br> <br>A Software Engineer'
        };

})();

推荐答案

有两种管理控制器的方法,您使用的是controller as方法,而大多数钓鱼者使用的另一种方法是$scope

There are 2 ways of managing your controller, you were going for the controller as approach and the other which is more widely used by most angularians is $scope.

文档

基本上$ scope注入到控制器中,并充当该容器的主要对象

Basically $scope is injected into the controller and acts a the main object for that container

app.controller('Ctrl', function ($scope) {
  $scope.product = {
    name: ...
  };
});
...
{{product.name}}

范围小提琴修复

controller as方法具有更大的灵活性,但也具有更多的原型复杂性.

The controller as method allows greater flexibility but also has more prototypical complexity.

app.controller('Controller', function () {
  this.product = {
    name: ...
  };
});

<div ng-controller="Controller as ctrl">
   {{ctrl.product.name}}
</div>

这篇关于角度不渲染&lt; br&gt;在我的json中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆